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
957unsafe extern "C" {
958    pub type ModuleBuffer;
959}
960
961pub type SelfProfileBeforePassCallback =
962    unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
963pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);
964
965pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void;
966pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;
967
968unsafe extern "C" {
969    // Create and destroy contexts.
970    pub(crate) fn LLVMContextDispose(C: &'static mut Context);
971    pub(crate) fn LLVMGetMDKindIDInContext(
972        C: &Context,
973        Name: *const c_char,
974        SLen: c_uint,
975    ) -> c_uint;
976
977    // Create modules.
978    pub(crate) fn LLVMModuleCreateWithNameInContext(
979        ModuleID: *const c_char,
980        C: &Context,
981    ) -> &Module;
982    pub(crate) fn LLVMCloneModule(M: &Module) -> &Module;
983
984    /// Data layout. See Module::getDataLayout.
985    pub(crate) fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char;
986    pub(crate) fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
987
988    /// See Module::setModuleInlineAsm.
989    pub(crate) fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t);
990
991    // Operations on integer types
992    pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type;
993    pub(crate) fn LLVMInt8TypeInContext(C: &Context) -> &Type;
994    pub(crate) fn LLVMInt16TypeInContext(C: &Context) -> &Type;
995    pub(crate) fn LLVMInt32TypeInContext(C: &Context) -> &Type;
996    pub(crate) fn LLVMInt64TypeInContext(C: &Context) -> &Type;
997    pub(crate) fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;
998
999    pub(crate) fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
1000
1001    // Operations on real types
1002    pub(crate) fn LLVMHalfTypeInContext(C: &Context) -> &Type;
1003    pub(crate) fn LLVMFloatTypeInContext(C: &Context) -> &Type;
1004    pub(crate) fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
1005    pub(crate) fn LLVMFP128TypeInContext(C: &Context) -> &Type;
1006
1007    // Operations on function types
1008    pub(crate) fn LLVMFunctionType<'a>(
1009        ReturnType: &'a Type,
1010        ParamTypes: *const &'a Type,
1011        ParamCount: c_uint,
1012        IsVarArg: Bool,
1013    ) -> &'a Type;
1014    pub(crate) fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;
1015    pub(crate) fn LLVMGetParamTypes<'a>(FunctionTy: &'a Type, Dest: *mut &'a Type);
1016
1017    // Operations on struct types
1018    pub(crate) fn LLVMStructTypeInContext<'a>(
1019        C: &'a Context,
1020        ElementTypes: *const &'a Type,
1021        ElementCount: c_uint,
1022        Packed: Bool,
1023    ) -> &'a Type;
1024
1025    // Operations on array, pointer, and vector types (sequence types)
1026    pub(crate) fn LLVMPointerTypeInContext(C: &Context, AddressSpace: c_uint) -> &Type;
1027    pub(crate) fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
1028
1029    pub(crate) fn LLVMGetElementType(Ty: &Type) -> &Type;
1030    pub(crate) fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;
1031
1032    // Operations on other types
1033    pub(crate) fn LLVMVoidTypeInContext(C: &Context) -> &Type;
1034    pub(crate) fn LLVMTokenTypeInContext(C: &Context) -> &Type;
1035    pub(crate) fn LLVMMetadataTypeInContext(C: &Context) -> &Type;
1036
1037    // Operations on all values
1038    pub(crate) fn LLVMTypeOf(Val: &Value) -> &Type;
1039    pub(crate) fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char;
1040    pub(crate) fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t);
1041    pub(crate) fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value);
1042    pub(crate) fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Node: &'a Value);
1043    pub(crate) fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
1044    pub(crate) fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;
1045
1046    // Operations on constants of any type
1047    pub(crate) fn LLVMConstNull(Ty: &Type) -> &Value;
1048    pub(crate) fn LLVMGetUndef(Ty: &Type) -> &Value;
1049    pub(crate) fn LLVMGetPoison(Ty: &Type) -> &Value;
1050
1051    // Operations on metadata
1052    pub(crate) fn LLVMMDStringInContext2(
1053        C: &Context,
1054        Str: *const c_char,
1055        SLen: size_t,
1056    ) -> &Metadata;
1057    pub(crate) fn LLVMMDNodeInContext2<'a>(
1058        C: &'a Context,
1059        Vals: *const &'a Metadata,
1060        Count: size_t,
1061    ) -> &'a Metadata;
1062    pub(crate) fn LLVMAddNamedMetadataOperand<'a>(
1063        M: &'a Module,
1064        Name: *const c_char,
1065        Val: &'a Value,
1066    );
1067
1068    // Operations on scalar constants
1069    pub(crate) fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
1070    pub(crate) fn LLVMConstIntOfArbitraryPrecision(
1071        IntTy: &Type,
1072        Wn: c_uint,
1073        Ws: *const u64,
1074    ) -> &Value;
1075    pub(crate) fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
1076
1077    // Operations on composite constants
1078    pub(crate) fn LLVMConstArray2<'a>(
1079        ElementTy: &'a Type,
1080        ConstantVals: *const &'a Value,
1081        Length: u64,
1082    ) -> &'a Value;
1083    pub(crate) fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type;
1084    pub(crate) fn LLVMConstStringInContext2(
1085        C: &Context,
1086        Str: *const c_char,
1087        Length: size_t,
1088        DontNullTerminate: Bool,
1089    ) -> &Value;
1090    pub(crate) fn LLVMConstStructInContext<'a>(
1091        C: &'a Context,
1092        ConstantVals: *const &'a Value,
1093        Count: c_uint,
1094        Packed: Bool,
1095    ) -> &'a Value;
1096    pub(crate) fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
1097
1098    // Constant expressions
1099    pub(crate) fn LLVMConstInBoundsGEP2<'a>(
1100        ty: &'a Type,
1101        ConstantVal: &'a Value,
1102        ConstantIndices: *const &'a Value,
1103        NumIndices: c_uint,
1104    ) -> &'a Value;
1105    pub(crate) fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1106    pub(crate) fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1107    pub(crate) fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1108    pub(crate) fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1109    pub(crate) fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>;
1110    pub(crate) fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode;
1111    pub(crate) fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>;
1112
1113    // Operations on global variables, functions, and aliases (globals)
1114    pub(crate) fn LLVMIsDeclaration(Global: &Value) -> Bool;
1115    pub(crate) fn LLVMGetLinkage(Global: &Value) -> RawEnum<Linkage>;
1116    pub(crate) fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage);
1117    pub(crate) fn LLVMSetSection(Global: &Value, Section: *const c_char);
1118    pub(crate) fn LLVMGetVisibility(Global: &Value) -> RawEnum<Visibility>;
1119    pub(crate) fn LLVMSetVisibility(Global: &Value, Viz: Visibility);
1120    pub(crate) fn LLVMGetAlignment(Global: &Value) -> c_uint;
1121    pub(crate) fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
1122    pub(crate) fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
1123    pub(crate) fn LLVMGlobalGetValueType(Global: &Value) -> &Type;
1124
1125    // Operations on global variables
1126    pub(crate) fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
1127    pub(crate) fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1128    pub(crate) fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
1129    pub(crate) fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
1130    pub(crate) fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
1131    pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value);
1132    pub(crate) fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
1133    pub(crate) fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value);
1134    pub(crate) fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool;
1135    pub(crate) fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
1136    pub(crate) fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
1137    pub(crate) fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
1138    pub(crate) fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1139
1140    // Operations on attributes
1141    pub(crate) fn LLVMCreateStringAttribute(
1142        C: &Context,
1143        Name: *const c_char,
1144        NameLen: c_uint,
1145        Value: *const c_char,
1146        ValueLen: c_uint,
1147    ) -> &Attribute;
1148
1149    // Operations on functions
1150    pub(crate) fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
1151
1152    // Operations on parameters
1153    pub(crate) fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
1154    pub(crate) fn LLVMCountParams(Fn: &Value) -> c_uint;
1155    pub(crate) fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
1156
1157    // Operations on basic blocks
1158    pub(crate) fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
1159    pub(crate) fn LLVMAppendBasicBlockInContext<'a>(
1160        C: &'a Context,
1161        Fn: &'a Value,
1162        Name: *const c_char,
1163    ) -> &'a BasicBlock;
1164
1165    // Operations on instructions
1166    pub(crate) fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
1167    pub(crate) fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
1168    pub(crate) fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>;
1169
1170    // Operations on call sites
1171    pub(crate) fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
1172
1173    // Operations on load/store instructions (only)
1174    pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
1175
1176    // Operations on phi nodes
1177    pub(crate) fn LLVMAddIncoming<'a>(
1178        PhiNode: &'a Value,
1179        IncomingValues: *const &'a Value,
1180        IncomingBlocks: *const &'a BasicBlock,
1181        Count: c_uint,
1182    );
1183
1184    // Instruction builders
1185    pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
1186    pub(crate) fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);
1187    pub(crate) fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock;
1188    pub(crate) fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
1189
1190    // Metadata
1191    pub(crate) fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: *const Metadata);
1192    pub(crate) fn LLVMGetCurrentDebugLocation2<'a>(Builder: &Builder<'a>) -> Option<&'a Metadata>;
1193
1194    // Terminators
1195    pub(crate) fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;
1196    pub(crate) fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value;
1197    pub(crate) fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
1198    pub(crate) fn LLVMBuildCondBr<'a>(
1199        B: &Builder<'a>,
1200        If: &'a Value,
1201        Then: &'a BasicBlock,
1202        Else: &'a BasicBlock,
1203    ) -> &'a Value;
1204    pub(crate) fn LLVMBuildSwitch<'a>(
1205        B: &Builder<'a>,
1206        V: &'a Value,
1207        Else: &'a BasicBlock,
1208        NumCases: c_uint,
1209    ) -> &'a Value;
1210    pub(crate) fn LLVMBuildLandingPad<'a>(
1211        B: &Builder<'a>,
1212        Ty: &'a Type,
1213        PersFn: Option<&'a Value>,
1214        NumClauses: c_uint,
1215        Name: *const c_char,
1216    ) -> &'a Value;
1217    pub(crate) fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
1218    pub(crate) fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;
1219
1220    pub(crate) fn LLVMBuildCleanupPad<'a>(
1221        B: &Builder<'a>,
1222        ParentPad: Option<&'a Value>,
1223        Args: *const &'a Value,
1224        NumArgs: c_uint,
1225        Name: *const c_char,
1226    ) -> Option<&'a Value>;
1227    pub(crate) fn LLVMBuildCleanupRet<'a>(
1228        B: &Builder<'a>,
1229        CleanupPad: &'a Value,
1230        BB: Option<&'a BasicBlock>,
1231    ) -> Option<&'a Value>;
1232    pub(crate) fn LLVMBuildCatchPad<'a>(
1233        B: &Builder<'a>,
1234        ParentPad: &'a Value,
1235        Args: *const &'a Value,
1236        NumArgs: c_uint,
1237        Name: *const c_char,
1238    ) -> Option<&'a Value>;
1239    pub(crate) fn LLVMBuildCatchRet<'a>(
1240        B: &Builder<'a>,
1241        CatchPad: &'a Value,
1242        BB: &'a BasicBlock,
1243    ) -> Option<&'a Value>;
1244    pub(crate) fn LLVMBuildCatchSwitch<'a>(
1245        Builder: &Builder<'a>,
1246        ParentPad: Option<&'a Value>,
1247        UnwindBB: Option<&'a BasicBlock>,
1248        NumHandlers: c_uint,
1249        Name: *const c_char,
1250    ) -> Option<&'a Value>;
1251    pub(crate) fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock);
1252    pub(crate) fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);
1253
1254    // Add a case to the switch instruction
1255    pub(crate) fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
1256
1257    // Add a clause to the landing pad instruction
1258    pub(crate) fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value);
1259
1260    // Set the cleanup on a landing pad instruction
1261    pub(crate) fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
1262
1263    // Arithmetic
1264    pub(crate) fn LLVMBuildAdd<'a>(
1265        B: &Builder<'a>,
1266        LHS: &'a Value,
1267        RHS: &'a Value,
1268        Name: *const c_char,
1269    ) -> &'a Value;
1270    pub(crate) fn LLVMBuildFAdd<'a>(
1271        B: &Builder<'a>,
1272        LHS: &'a Value,
1273        RHS: &'a Value,
1274        Name: *const c_char,
1275    ) -> &'a Value;
1276    pub(crate) fn LLVMBuildSub<'a>(
1277        B: &Builder<'a>,
1278        LHS: &'a Value,
1279        RHS: &'a Value,
1280        Name: *const c_char,
1281    ) -> &'a Value;
1282    pub(crate) fn LLVMBuildFSub<'a>(
1283        B: &Builder<'a>,
1284        LHS: &'a Value,
1285        RHS: &'a Value,
1286        Name: *const c_char,
1287    ) -> &'a Value;
1288    pub(crate) fn LLVMBuildMul<'a>(
1289        B: &Builder<'a>,
1290        LHS: &'a Value,
1291        RHS: &'a Value,
1292        Name: *const c_char,
1293    ) -> &'a Value;
1294    pub(crate) fn LLVMBuildFMul<'a>(
1295        B: &Builder<'a>,
1296        LHS: &'a Value,
1297        RHS: &'a Value,
1298        Name: *const c_char,
1299    ) -> &'a Value;
1300    pub(crate) fn LLVMBuildUDiv<'a>(
1301        B: &Builder<'a>,
1302        LHS: &'a Value,
1303        RHS: &'a Value,
1304        Name: *const c_char,
1305    ) -> &'a Value;
1306    pub(crate) fn LLVMBuildExactUDiv<'a>(
1307        B: &Builder<'a>,
1308        LHS: &'a Value,
1309        RHS: &'a Value,
1310        Name: *const c_char,
1311    ) -> &'a Value;
1312    pub(crate) fn LLVMBuildSDiv<'a>(
1313        B: &Builder<'a>,
1314        LHS: &'a Value,
1315        RHS: &'a Value,
1316        Name: *const c_char,
1317    ) -> &'a Value;
1318    pub(crate) fn LLVMBuildExactSDiv<'a>(
1319        B: &Builder<'a>,
1320        LHS: &'a Value,
1321        RHS: &'a Value,
1322        Name: *const c_char,
1323    ) -> &'a Value;
1324    pub(crate) fn LLVMBuildFDiv<'a>(
1325        B: &Builder<'a>,
1326        LHS: &'a Value,
1327        RHS: &'a Value,
1328        Name: *const c_char,
1329    ) -> &'a Value;
1330    pub(crate) fn LLVMBuildURem<'a>(
1331        B: &Builder<'a>,
1332        LHS: &'a Value,
1333        RHS: &'a Value,
1334        Name: *const c_char,
1335    ) -> &'a Value;
1336    pub(crate) fn LLVMBuildSRem<'a>(
1337        B: &Builder<'a>,
1338        LHS: &'a Value,
1339        RHS: &'a Value,
1340        Name: *const c_char,
1341    ) -> &'a Value;
1342    pub(crate) fn LLVMBuildFRem<'a>(
1343        B: &Builder<'a>,
1344        LHS: &'a Value,
1345        RHS: &'a Value,
1346        Name: *const c_char,
1347    ) -> &'a Value;
1348    pub(crate) fn LLVMBuildShl<'a>(
1349        B: &Builder<'a>,
1350        LHS: &'a Value,
1351        RHS: &'a Value,
1352        Name: *const c_char,
1353    ) -> &'a Value;
1354    pub(crate) fn LLVMBuildLShr<'a>(
1355        B: &Builder<'a>,
1356        LHS: &'a Value,
1357        RHS: &'a Value,
1358        Name: *const c_char,
1359    ) -> &'a Value;
1360    pub(crate) fn LLVMBuildAShr<'a>(
1361        B: &Builder<'a>,
1362        LHS: &'a Value,
1363        RHS: &'a Value,
1364        Name: *const c_char,
1365    ) -> &'a Value;
1366    pub(crate) fn LLVMBuildNSWAdd<'a>(
1367        B: &Builder<'a>,
1368        LHS: &'a Value,
1369        RHS: &'a Value,
1370        Name: *const c_char,
1371    ) -> &'a Value;
1372    pub(crate) fn LLVMBuildNUWAdd<'a>(
1373        B: &Builder<'a>,
1374        LHS: &'a Value,
1375        RHS: &'a Value,
1376        Name: *const c_char,
1377    ) -> &'a Value;
1378    pub(crate) fn LLVMBuildNSWSub<'a>(
1379        B: &Builder<'a>,
1380        LHS: &'a Value,
1381        RHS: &'a Value,
1382        Name: *const c_char,
1383    ) -> &'a Value;
1384    pub(crate) fn LLVMBuildNUWSub<'a>(
1385        B: &Builder<'a>,
1386        LHS: &'a Value,
1387        RHS: &'a Value,
1388        Name: *const c_char,
1389    ) -> &'a Value;
1390    pub(crate) fn LLVMBuildNSWMul<'a>(
1391        B: &Builder<'a>,
1392        LHS: &'a Value,
1393        RHS: &'a Value,
1394        Name: *const c_char,
1395    ) -> &'a Value;
1396    pub(crate) fn LLVMBuildNUWMul<'a>(
1397        B: &Builder<'a>,
1398        LHS: &'a Value,
1399        RHS: &'a Value,
1400        Name: *const c_char,
1401    ) -> &'a Value;
1402    pub(crate) fn LLVMBuildAnd<'a>(
1403        B: &Builder<'a>,
1404        LHS: &'a Value,
1405        RHS: &'a Value,
1406        Name: *const c_char,
1407    ) -> &'a Value;
1408    pub(crate) fn LLVMBuildOr<'a>(
1409        B: &Builder<'a>,
1410        LHS: &'a Value,
1411        RHS: &'a Value,
1412        Name: *const c_char,
1413    ) -> &'a Value;
1414    pub(crate) fn LLVMBuildXor<'a>(
1415        B: &Builder<'a>,
1416        LHS: &'a Value,
1417        RHS: &'a Value,
1418        Name: *const c_char,
1419    ) -> &'a Value;
1420    pub(crate) fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char)
1421    -> &'a Value;
1422    pub(crate) fn LLVMBuildFNeg<'a>(
1423        B: &Builder<'a>,
1424        V: &'a Value,
1425        Name: *const c_char,
1426    ) -> &'a Value;
1427    pub(crate) fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char)
1428    -> &'a Value;
1429
1430    // Extra flags on arithmetic
1431    pub(crate) fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool);
1432    pub(crate) fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool);
1433    pub(crate) fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool);
1434
1435    // Memory
1436    pub(crate) fn LLVMBuildAlloca<'a>(
1437        B: &Builder<'a>,
1438        Ty: &'a Type,
1439        Name: *const c_char,
1440    ) -> &'a Value;
1441    pub(crate) fn LLVMBuildArrayAlloca<'a>(
1442        B: &Builder<'a>,
1443        Ty: &'a Type,
1444        Val: &'a Value,
1445        Name: *const c_char,
1446    ) -> &'a Value;
1447    pub(crate) fn LLVMBuildLoad2<'a>(
1448        B: &Builder<'a>,
1449        Ty: &'a Type,
1450        PointerVal: &'a Value,
1451        Name: *const c_char,
1452    ) -> &'a Value;
1453
1454    pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
1455
1456    pub(crate) fn LLVMBuildGEP2<'a>(
1457        B: &Builder<'a>,
1458        Ty: &'a Type,
1459        Pointer: &'a Value,
1460        Indices: *const &'a Value,
1461        NumIndices: c_uint,
1462        Name: *const c_char,
1463    ) -> &'a Value;
1464    pub(crate) fn LLVMBuildInBoundsGEP2<'a>(
1465        B: &Builder<'a>,
1466        Ty: &'a Type,
1467        Pointer: &'a Value,
1468        Indices: *const &'a Value,
1469        NumIndices: c_uint,
1470        Name: *const c_char,
1471    ) -> &'a Value;
1472
1473    // Casts
1474    pub(crate) fn LLVMBuildTrunc<'a>(
1475        B: &Builder<'a>,
1476        Val: &'a Value,
1477        DestTy: &'a Type,
1478        Name: *const c_char,
1479    ) -> &'a Value;
1480    pub(crate) fn LLVMBuildZExt<'a>(
1481        B: &Builder<'a>,
1482        Val: &'a Value,
1483        DestTy: &'a Type,
1484        Name: *const c_char,
1485    ) -> &'a Value;
1486    pub(crate) fn LLVMBuildSExt<'a>(
1487        B: &Builder<'a>,
1488        Val: &'a Value,
1489        DestTy: &'a Type,
1490        Name: *const c_char,
1491    ) -> &'a Value;
1492    pub(crate) fn LLVMBuildFPToUI<'a>(
1493        B: &Builder<'a>,
1494        Val: &'a Value,
1495        DestTy: &'a Type,
1496        Name: *const c_char,
1497    ) -> &'a Value;
1498    pub(crate) fn LLVMBuildFPToSI<'a>(
1499        B: &Builder<'a>,
1500        Val: &'a Value,
1501        DestTy: &'a Type,
1502        Name: *const c_char,
1503    ) -> &'a Value;
1504    pub(crate) fn LLVMBuildUIToFP<'a>(
1505        B: &Builder<'a>,
1506        Val: &'a Value,
1507        DestTy: &'a Type,
1508        Name: *const c_char,
1509    ) -> &'a Value;
1510    pub(crate) fn LLVMBuildSIToFP<'a>(
1511        B: &Builder<'a>,
1512        Val: &'a Value,
1513        DestTy: &'a Type,
1514        Name: *const c_char,
1515    ) -> &'a Value;
1516    pub(crate) fn LLVMBuildFPTrunc<'a>(
1517        B: &Builder<'a>,
1518        Val: &'a Value,
1519        DestTy: &'a Type,
1520        Name: *const c_char,
1521    ) -> &'a Value;
1522    pub(crate) fn LLVMBuildFPExt<'a>(
1523        B: &Builder<'a>,
1524        Val: &'a Value,
1525        DestTy: &'a Type,
1526        Name: *const c_char,
1527    ) -> &'a Value;
1528    pub(crate) fn LLVMBuildPtrToInt<'a>(
1529        B: &Builder<'a>,
1530        Val: &'a Value,
1531        DestTy: &'a Type,
1532        Name: *const c_char,
1533    ) -> &'a Value;
1534    pub(crate) fn LLVMBuildIntToPtr<'a>(
1535        B: &Builder<'a>,
1536        Val: &'a Value,
1537        DestTy: &'a Type,
1538        Name: *const c_char,
1539    ) -> &'a Value;
1540    pub(crate) fn LLVMBuildBitCast<'a>(
1541        B: &Builder<'a>,
1542        Val: &'a Value,
1543        DestTy: &'a Type,
1544        Name: *const c_char,
1545    ) -> &'a Value;
1546    pub(crate) fn LLVMBuildPointerCast<'a>(
1547        B: &Builder<'a>,
1548        Val: &'a Value,
1549        DestTy: &'a Type,
1550        Name: *const c_char,
1551    ) -> &'a Value;
1552    pub(crate) fn LLVMBuildIntCast2<'a>(
1553        B: &Builder<'a>,
1554        Val: &'a Value,
1555        DestTy: &'a Type,
1556        IsSigned: Bool,
1557        Name: *const c_char,
1558    ) -> &'a Value;
1559
1560    // Comparisons
1561    pub(crate) fn LLVMBuildICmp<'a>(
1562        B: &Builder<'a>,
1563        Op: c_uint,
1564        LHS: &'a Value,
1565        RHS: &'a Value,
1566        Name: *const c_char,
1567    ) -> &'a Value;
1568    pub(crate) fn LLVMBuildFCmp<'a>(
1569        B: &Builder<'a>,
1570        Op: c_uint,
1571        LHS: &'a Value,
1572        RHS: &'a Value,
1573        Name: *const c_char,
1574    ) -> &'a Value;
1575
1576    // Miscellaneous instructions
1577    pub(crate) fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char)
1578    -> &'a Value;
1579    pub(crate) fn LLVMBuildSelect<'a>(
1580        B: &Builder<'a>,
1581        If: &'a Value,
1582        Then: &'a Value,
1583        Else: &'a Value,
1584        Name: *const c_char,
1585    ) -> &'a Value;
1586    pub(crate) fn LLVMBuildVAArg<'a>(
1587        B: &Builder<'a>,
1588        list: &'a Value,
1589        Ty: &'a Type,
1590        Name: *const c_char,
1591    ) -> &'a Value;
1592    pub(crate) fn LLVMBuildExtractElement<'a>(
1593        B: &Builder<'a>,
1594        VecVal: &'a Value,
1595        Index: &'a Value,
1596        Name: *const c_char,
1597    ) -> &'a Value;
1598    pub(crate) fn LLVMBuildInsertElement<'a>(
1599        B: &Builder<'a>,
1600        VecVal: &'a Value,
1601        EltVal: &'a Value,
1602        Index: &'a Value,
1603        Name: *const c_char,
1604    ) -> &'a Value;
1605    pub(crate) fn LLVMBuildShuffleVector<'a>(
1606        B: &Builder<'a>,
1607        V1: &'a Value,
1608        V2: &'a Value,
1609        Mask: &'a Value,
1610        Name: *const c_char,
1611    ) -> &'a Value;
1612    pub(crate) fn LLVMBuildExtractValue<'a>(
1613        B: &Builder<'a>,
1614        AggVal: &'a Value,
1615        Index: c_uint,
1616        Name: *const c_char,
1617    ) -> &'a Value;
1618    pub(crate) fn LLVMBuildInsertValue<'a>(
1619        B: &Builder<'a>,
1620        AggVal: &'a Value,
1621        EltVal: &'a Value,
1622        Index: c_uint,
1623        Name: *const c_char,
1624    ) -> &'a Value;
1625
1626    // Atomic Operations
1627    pub(crate) fn LLVMBuildAtomicCmpXchg<'a>(
1628        B: &Builder<'a>,
1629        LHS: &'a Value,
1630        CMP: &'a Value,
1631        RHS: &'a Value,
1632        Order: AtomicOrdering,
1633        FailureOrder: AtomicOrdering,
1634        SingleThreaded: Bool,
1635    ) -> &'a Value;
1636
1637    pub(crate) fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);
1638
1639    pub(crate) fn LLVMBuildAtomicRMW<'a>(
1640        B: &Builder<'a>,
1641        Op: AtomicRmwBinOp,
1642        LHS: &'a Value,
1643        RHS: &'a Value,
1644        Order: AtomicOrdering,
1645        SingleThreaded: Bool,
1646    ) -> &'a Value;
1647
1648    pub(crate) fn LLVMBuildFence<'a>(
1649        B: &Builder<'a>,
1650        Order: AtomicOrdering,
1651        SingleThreaded: Bool,
1652        Name: *const c_char,
1653    ) -> &'a Value;
1654
1655    /// Writes a module to the specified path. Returns 0 on success.
1656    pub(crate) fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1657
1658    /// Creates a legacy pass manager -- only used for final codegen.
1659    pub(crate) fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
1660
1661    pub(crate) fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
1662
1663    pub(crate) fn LLVMGetHostCPUFeatures() -> *mut c_char;
1664
1665    pub(crate) fn LLVMDisposeMessage(message: *mut c_char);
1666
1667    pub(crate) fn LLVMIsMultithreaded() -> Bool;
1668
1669    pub(crate) fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1670
1671    pub(crate) fn LLVMStructSetBody<'a>(
1672        StructTy: &'a Type,
1673        ElementTypes: *const &'a Type,
1674        ElementCount: c_uint,
1675        Packed: Bool,
1676    );
1677
1678    pub(crate) fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1679
1680    pub(crate) fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
1681
1682    pub(crate) fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
1683
1684    pub(crate) fn LLVMGetOrInsertComdat(M: &Module, Name: *const c_char) -> &Comdat;
1685    pub(crate) fn LLVMSetComdat(V: &Value, C: &Comdat);
1686
1687    pub(crate) fn LLVMCreateOperandBundle(
1688        Tag: *const c_char,
1689        TagLen: size_t,
1690        Args: *const &'_ Value,
1691        NumArgs: c_uint,
1692    ) -> *mut OperandBundle<'_>;
1693    pub(crate) fn LLVMDisposeOperandBundle(Bundle: ptr::NonNull<OperandBundle<'_>>);
1694
1695    pub(crate) fn LLVMBuildCallWithOperandBundles<'a>(
1696        B: &Builder<'a>,
1697        Ty: &'a Type,
1698        Fn: &'a Value,
1699        Args: *const &'a Value,
1700        NumArgs: c_uint,
1701        Bundles: *const &OperandBundle<'a>,
1702        NumBundles: c_uint,
1703        Name: *const c_char,
1704    ) -> &'a Value;
1705    pub(crate) fn LLVMBuildInvokeWithOperandBundles<'a>(
1706        B: &Builder<'a>,
1707        Ty: &'a Type,
1708        Fn: &'a Value,
1709        Args: *const &'a Value,
1710        NumArgs: c_uint,
1711        Then: &'a BasicBlock,
1712        Catch: &'a BasicBlock,
1713        Bundles: *const &OperandBundle<'a>,
1714        NumBundles: c_uint,
1715        Name: *const c_char,
1716    ) -> &'a Value;
1717    pub(crate) fn LLVMBuildCallBr<'a>(
1718        B: &Builder<'a>,
1719        Ty: &'a Type,
1720        Fn: &'a Value,
1721        DefaultDest: &'a BasicBlock,
1722        IndirectDests: *const &'a BasicBlock,
1723        NumIndirectDests: c_uint,
1724        Args: *const &'a Value,
1725        NumArgs: c_uint,
1726        Bundles: *const &OperandBundle<'a>,
1727        NumBundles: c_uint,
1728        Name: *const c_char,
1729    ) -> &'a Value;
1730}
1731
1732// FFI bindings for `DIBuilder` functions in the LLVM-C API.
1733// Try to keep these in the same order as in `llvm/include/llvm-c/DebugInfo.h`.
1734//
1735// FIXME(#134001): Audit all `Option` parameters, especially in lists, to check
1736// that they really are nullable on the C/C++ side. LLVM doesn't appear to
1737// actually document which ones are nullable.
1738unsafe extern "C" {
1739    pub(crate) fn LLVMCreateDIBuilder<'ll>(M: &'ll Module) -> *mut DIBuilder<'ll>;
1740    pub(crate) fn LLVMDisposeDIBuilder<'ll>(Builder: ptr::NonNull<DIBuilder<'ll>>);
1741
1742    pub(crate) fn LLVMDIBuilderFinalize<'ll>(Builder: &DIBuilder<'ll>);
1743
1744    pub(crate) fn LLVMDIBuilderCreateNameSpace<'ll>(
1745        Builder: &DIBuilder<'ll>,
1746        ParentScope: Option<&'ll Metadata>,
1747        Name: *const c_uchar,
1748        NameLen: size_t,
1749        ExportSymbols: llvm::Bool,
1750    ) -> &'ll Metadata;
1751
1752    pub(crate) fn LLVMDIBuilderCreateLexicalBlock<'ll>(
1753        Builder: &DIBuilder<'ll>,
1754        Scope: &'ll Metadata,
1755        File: &'ll Metadata,
1756        Line: c_uint,
1757        Column: c_uint,
1758    ) -> &'ll Metadata;
1759
1760    pub(crate) fn LLVMDIBuilderCreateLexicalBlockFile<'ll>(
1761        Builder: &DIBuilder<'ll>,
1762        Scope: &'ll Metadata,
1763        File: &'ll Metadata,
1764        Discriminator: c_uint, // (optional "DWARF path discriminator"; default is 0)
1765    ) -> &'ll Metadata;
1766
1767    pub(crate) fn LLVMDIBuilderCreateDebugLocation<'ll>(
1768        Ctx: &'ll Context,
1769        Line: c_uint,
1770        Column: c_uint,
1771        Scope: &'ll Metadata,
1772        InlinedAt: Option<&'ll Metadata>,
1773    ) -> &'ll Metadata;
1774}
1775
1776#[link(name = "llvm-wrapper", kind = "static")]
1777unsafe extern "C" {
1778    pub(crate) fn LLVMRustInstallErrorHandlers();
1779    pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();
1780
1781    // Create and destroy contexts.
1782    pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
1783
1784    /// See llvm::LLVMTypeKind::getTypeID.
1785    pub(crate) fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
1786
1787    // Operations on all values
1788    pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
1789        Val: &'a Value,
1790        KindID: c_uint,
1791        Metadata: &'a Metadata,
1792    );
1793    pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;
1794
1795    // Operations on scalar constants
1796    pub(crate) fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
1797    pub(crate) fn LLVMRustConstInt128Get(
1798        ConstantVal: &ConstantInt,
1799        SExt: bool,
1800        high: &mut u64,
1801        low: &mut u64,
1802    ) -> bool;
1803
1804    // Operations on global variables, functions, and aliases (globals)
1805    pub(crate) fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
1806
1807    // Operations on global variables
1808    pub(crate) fn LLVMRustGetOrInsertGlobal<'a>(
1809        M: &'a Module,
1810        Name: *const c_char,
1811        NameLen: size_t,
1812        T: &'a Type,
1813    ) -> &'a Value;
1814    pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
1815    pub(crate) fn LLVMRustGetNamedValue(
1816        M: &Module,
1817        Name: *const c_char,
1818        NameLen: size_t,
1819    ) -> Option<&Value>;
1820
1821    // Operations on attributes
1822    pub(crate) fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
1823    pub(crate) fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute;
1824    pub(crate) fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute;
1825    pub(crate) fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute;
1826    pub(crate) fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1827    pub(crate) fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1828    pub(crate) fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1829    pub(crate) fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
1830    pub(crate) fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute;
1831    pub(crate) fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute;
1832    pub(crate) fn LLVMRustCreateMemoryEffectsAttr(
1833        C: &Context,
1834        effects: MemoryEffects,
1835    ) -> &Attribute;
1836    pub(crate) fn LLVMRustCreateRangeAttribute(
1837        C: &Context,
1838        num_bits: c_uint,
1839        lower_words: *const u64,
1840        upper_words: *const u64,
1841    ) -> &Attribute;
1842
1843    // Operations on functions
1844    pub(crate) fn LLVMRustGetOrInsertFunction<'a>(
1845        M: &'a Module,
1846        Name: *const c_char,
1847        NameLen: size_t,
1848        FunctionTy: &'a Type,
1849    ) -> &'a Value;
1850    pub(crate) fn LLVMRustAddFunctionAttributes<'a>(
1851        Fn: &'a Value,
1852        index: c_uint,
1853        Attrs: *const &'a Attribute,
1854        AttrsLen: size_t,
1855    );
1856
1857    // Operations on call sites
1858    pub(crate) fn LLVMRustAddCallSiteAttributes<'a>(
1859        Instr: &'a Value,
1860        index: c_uint,
1861        Attrs: *const &'a Attribute,
1862        AttrsLen: size_t,
1863    );
1864
1865    pub(crate) fn LLVMRustSetFastMath(Instr: &Value);
1866    pub(crate) fn LLVMRustSetAlgebraicMath(Instr: &Value);
1867    pub(crate) fn LLVMRustSetAllowReassoc(Instr: &Value);
1868
1869    // Miscellaneous instructions
1870    pub(crate) fn LLVMRustBuildMemCpy<'a>(
1871        B: &Builder<'a>,
1872        Dst: &'a Value,
1873        DstAlign: c_uint,
1874        Src: &'a Value,
1875        SrcAlign: c_uint,
1876        Size: &'a Value,
1877        IsVolatile: bool,
1878    ) -> &'a Value;
1879    pub(crate) fn LLVMRustBuildMemMove<'a>(
1880        B: &Builder<'a>,
1881        Dst: &'a Value,
1882        DstAlign: c_uint,
1883        Src: &'a Value,
1884        SrcAlign: c_uint,
1885        Size: &'a Value,
1886        IsVolatile: bool,
1887    ) -> &'a Value;
1888    pub(crate) fn LLVMRustBuildMemSet<'a>(
1889        B: &Builder<'a>,
1890        Dst: &'a Value,
1891        DstAlign: c_uint,
1892        Val: &'a Value,
1893        Size: &'a Value,
1894        IsVolatile: bool,
1895    ) -> &'a Value;
1896
1897    pub(crate) fn LLVMRustBuildVectorReduceFAdd<'a>(
1898        B: &Builder<'a>,
1899        Acc: &'a Value,
1900        Src: &'a Value,
1901    ) -> &'a Value;
1902    pub(crate) fn LLVMRustBuildVectorReduceFMul<'a>(
1903        B: &Builder<'a>,
1904        Acc: &'a Value,
1905        Src: &'a Value,
1906    ) -> &'a Value;
1907    pub(crate) fn LLVMRustBuildVectorReduceAdd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1908    pub(crate) fn LLVMRustBuildVectorReduceMul<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1909    pub(crate) fn LLVMRustBuildVectorReduceAnd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1910    pub(crate) fn LLVMRustBuildVectorReduceOr<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1911    pub(crate) fn LLVMRustBuildVectorReduceXor<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1912    pub(crate) fn LLVMRustBuildVectorReduceMin<'a>(
1913        B: &Builder<'a>,
1914        Src: &'a Value,
1915        IsSigned: bool,
1916    ) -> &'a Value;
1917    pub(crate) fn LLVMRustBuildVectorReduceMax<'a>(
1918        B: &Builder<'a>,
1919        Src: &'a Value,
1920        IsSigned: bool,
1921    ) -> &'a Value;
1922    pub(crate) fn LLVMRustBuildVectorReduceFMin<'a>(
1923        B: &Builder<'a>,
1924        Src: &'a Value,
1925        IsNaN: bool,
1926    ) -> &'a Value;
1927    pub(crate) fn LLVMRustBuildVectorReduceFMax<'a>(
1928        B: &Builder<'a>,
1929        Src: &'a Value,
1930        IsNaN: bool,
1931    ) -> &'a Value;
1932
1933    pub(crate) fn LLVMRustBuildMinNum<'a>(
1934        B: &Builder<'a>,
1935        LHS: &'a Value,
1936        LHS: &'a Value,
1937    ) -> &'a Value;
1938    pub(crate) fn LLVMRustBuildMaxNum<'a>(
1939        B: &Builder<'a>,
1940        LHS: &'a Value,
1941        LHS: &'a Value,
1942    ) -> &'a Value;
1943
1944    // Atomic Operations
1945    pub(crate) fn LLVMRustBuildAtomicLoad<'a>(
1946        B: &Builder<'a>,
1947        ElementType: &'a Type,
1948        PointerVal: &'a Value,
1949        Name: *const c_char,
1950        Order: AtomicOrdering,
1951    ) -> &'a Value;
1952
1953    pub(crate) fn LLVMRustBuildAtomicStore<'a>(
1954        B: &Builder<'a>,
1955        Val: &'a Value,
1956        Ptr: &'a Value,
1957        Order: AtomicOrdering,
1958    ) -> &'a Value;
1959
1960    pub(crate) fn LLVMRustTimeTraceProfilerInitialize();
1961
1962    pub(crate) fn LLVMRustTimeTraceProfilerFinishThread();
1963
1964    pub(crate) fn LLVMRustTimeTraceProfilerFinish(FileName: *const c_char);
1965
1966    /// Returns a string describing the last error caused by an LLVMRust* call.
1967    pub(crate) fn LLVMRustGetLastError() -> *const c_char;
1968
1969    /// Prints the timing information collected by `-Ztime-llvm-passes`.
1970    pub(crate) fn LLVMRustPrintPassTimings(OutStr: &RustString);
1971
1972    /// Prints the statistics collected by `-Zprint-codegen-stats`.
1973    pub(crate) fn LLVMRustPrintStatistics(OutStr: &RustString);
1974
1975    /// Prepares inline assembly.
1976    pub(crate) fn LLVMRustInlineAsm(
1977        Ty: &Type,
1978        AsmString: *const c_char,
1979        AsmStringLen: size_t,
1980        Constraints: *const c_char,
1981        ConstraintsLen: size_t,
1982        SideEffects: Bool,
1983        AlignStack: Bool,
1984        Dialect: AsmDialect,
1985        CanThrow: Bool,
1986    ) -> &Value;
1987    pub(crate) fn LLVMRustInlineAsmVerify(
1988        Ty: &Type,
1989        Constraints: *const c_char,
1990        ConstraintsLen: size_t,
1991    ) -> bool;
1992
1993    pub(crate) fn LLVMRustCoverageWriteFilenamesToBuffer(
1994        Filenames: *const *const c_char,
1995        FilenamesLen: size_t,
1996        Lengths: *const size_t,
1997        LengthsLen: size_t,
1998        BufferOut: &RustString,
1999    );
2000
2001    pub(crate) fn LLVMRustCoverageWriteFunctionMappingsToBuffer(
2002        VirtualFileMappingIDs: *const c_uint,
2003        NumVirtualFileMappingIDs: size_t,
2004        Expressions: *const crate::coverageinfo::ffi::CounterExpression,
2005        NumExpressions: size_t,
2006        CodeRegions: *const crate::coverageinfo::ffi::CodeRegion,
2007        NumCodeRegions: size_t,
2008        BranchRegions: *const crate::coverageinfo::ffi::BranchRegion,
2009        NumBranchRegions: size_t,
2010        MCDCBranchRegions: *const crate::coverageinfo::ffi::MCDCBranchRegion,
2011        NumMCDCBranchRegions: size_t,
2012        MCDCDecisionRegions: *const crate::coverageinfo::ffi::MCDCDecisionRegion,
2013        NumMCDCDecisionRegions: size_t,
2014        BufferOut: &RustString,
2015    );
2016
2017    pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar(
2018        F: &Value,
2019        FuncName: *const c_char,
2020        FuncNameLen: size_t,
2021    ) -> &Value;
2022    pub(crate) fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64;
2023
2024    pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString);
2025
2026    pub(crate) fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString);
2027
2028    pub(crate) fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
2029
2030    pub(crate) fn LLVMRustCoverageMappingVersion() -> u32;
2031    pub(crate) fn LLVMRustDebugMetadataVersion() -> u32;
2032    pub(crate) fn LLVMRustVersionMajor() -> u32;
2033    pub(crate) fn LLVMRustVersionMinor() -> u32;
2034    pub(crate) fn LLVMRustVersionPatch() -> u32;
2035
2036    /// Add LLVM module flags.
2037    ///
2038    /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What
2039    /// "compatible" means depends on the merge behaviors involved.
2040    pub(crate) fn LLVMRustAddModuleFlagU32(
2041        M: &Module,
2042        MergeBehavior: ModuleFlagMergeBehavior,
2043        Name: *const c_char,
2044        NameLen: size_t,
2045        Value: u32,
2046    );
2047
2048    pub(crate) fn LLVMRustAddModuleFlagString(
2049        M: &Module,
2050        MergeBehavior: ModuleFlagMergeBehavior,
2051        Name: *const c_char,
2052        NameLen: size_t,
2053        Value: *const c_char,
2054        ValueLen: size_t,
2055    );
2056
2057    pub(crate) fn LLVMRustDIBuilderCreateCompileUnit<'a>(
2058        Builder: &DIBuilder<'a>,
2059        Lang: c_uint,
2060        File: &'a DIFile,
2061        Producer: *const c_char,
2062        ProducerLen: size_t,
2063        isOptimized: bool,
2064        Flags: *const c_char,
2065        RuntimeVer: c_uint,
2066        SplitName: *const c_char,
2067        SplitNameLen: size_t,
2068        kind: DebugEmissionKind,
2069        DWOId: u64,
2070        SplitDebugInlining: bool,
2071        DebugNameTableKind: DebugNameTableKind,
2072    ) -> &'a DIDescriptor;
2073
2074    pub(crate) fn LLVMRustDIBuilderCreateFile<'a>(
2075        Builder: &DIBuilder<'a>,
2076        Filename: *const c_char,
2077        FilenameLen: size_t,
2078        Directory: *const c_char,
2079        DirectoryLen: size_t,
2080        CSKind: ChecksumKind,
2081        Checksum: *const c_char,
2082        ChecksumLen: size_t,
2083        Source: *const c_char,
2084        SourceLen: size_t,
2085    ) -> &'a DIFile;
2086
2087    pub(crate) fn LLVMRustDIBuilderCreateSubroutineType<'a>(
2088        Builder: &DIBuilder<'a>,
2089        ParameterTypes: &'a DIArray,
2090    ) -> &'a DICompositeType;
2091
2092    pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>(
2093        Builder: &DIBuilder<'a>,
2094        Scope: &'a DIDescriptor,
2095        Name: *const c_char,
2096        NameLen: size_t,
2097        LinkageName: *const c_char,
2098        LinkageNameLen: size_t,
2099        File: &'a DIFile,
2100        LineNo: c_uint,
2101        Ty: &'a DIType,
2102        ScopeLine: c_uint,
2103        Flags: DIFlags,
2104        SPFlags: DISPFlags,
2105        MaybeFn: Option<&'a Value>,
2106        TParam: &'a DIArray,
2107        Decl: Option<&'a DIDescriptor>,
2108    ) -> &'a DISubprogram;
2109
2110    pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>(
2111        Builder: &DIBuilder<'a>,
2112        Scope: &'a DIDescriptor,
2113        Name: *const c_char,
2114        NameLen: size_t,
2115        LinkageName: *const c_char,
2116        LinkageNameLen: size_t,
2117        File: &'a DIFile,
2118        LineNo: c_uint,
2119        Ty: &'a DIType,
2120        Flags: DIFlags,
2121        SPFlags: DISPFlags,
2122        TParam: &'a DIArray,
2123    ) -> &'a DISubprogram;
2124
2125    pub(crate) fn LLVMRustDIBuilderCreateBasicType<'a>(
2126        Builder: &DIBuilder<'a>,
2127        Name: *const c_char,
2128        NameLen: size_t,
2129        SizeInBits: u64,
2130        Encoding: c_uint,
2131    ) -> &'a DIBasicType;
2132
2133    pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>(
2134        Builder: &DIBuilder<'a>,
2135        Type: &'a DIBasicType,
2136        Name: *const c_char,
2137        NameLen: size_t,
2138        File: &'a DIFile,
2139        LineNo: c_uint,
2140        Scope: Option<&'a DIScope>,
2141    ) -> &'a DIDerivedType;
2142
2143    pub(crate) fn LLVMRustDIBuilderCreatePointerType<'a>(
2144        Builder: &DIBuilder<'a>,
2145        PointeeTy: &'a DIType,
2146        SizeInBits: u64,
2147        AlignInBits: u32,
2148        AddressSpace: c_uint,
2149        Name: *const c_char,
2150        NameLen: size_t,
2151    ) -> &'a DIDerivedType;
2152
2153    pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>(
2154        Builder: &DIBuilder<'a>,
2155        Scope: Option<&'a DIDescriptor>,
2156        Name: *const c_char,
2157        NameLen: size_t,
2158        File: &'a DIFile,
2159        LineNumber: c_uint,
2160        SizeInBits: u64,
2161        AlignInBits: u32,
2162        Flags: DIFlags,
2163        DerivedFrom: Option<&'a DIType>,
2164        Elements: &'a DIArray,
2165        RunTimeLang: c_uint,
2166        VTableHolder: Option<&'a DIType>,
2167        UniqueId: *const c_char,
2168        UniqueIdLen: size_t,
2169    ) -> &'a DICompositeType;
2170
2171    pub(crate) fn LLVMRustDIBuilderCreateMemberType<'a>(
2172        Builder: &DIBuilder<'a>,
2173        Scope: &'a DIDescriptor,
2174        Name: *const c_char,
2175        NameLen: size_t,
2176        File: &'a DIFile,
2177        LineNo: c_uint,
2178        SizeInBits: u64,
2179        AlignInBits: u32,
2180        OffsetInBits: u64,
2181        Flags: DIFlags,
2182        Ty: &'a DIType,
2183    ) -> &'a DIDerivedType;
2184
2185    pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
2186        Builder: &DIBuilder<'a>,
2187        Scope: &'a DIScope,
2188        Name: *const c_char,
2189        NameLen: size_t,
2190        File: &'a DIFile,
2191        LineNumber: c_uint,
2192        SizeInBits: u64,
2193        AlignInBits: u32,
2194        OffsetInBits: u64,
2195        Discriminant: Option<&'a Value>,
2196        Flags: DIFlags,
2197        Ty: &'a DIType,
2198    ) -> &'a DIType;
2199
2200    pub(crate) fn LLVMRustDIBuilderCreateStaticMemberType<'a>(
2201        Builder: &DIBuilder<'a>,
2202        Scope: &'a DIDescriptor,
2203        Name: *const c_char,
2204        NameLen: size_t,
2205        File: &'a DIFile,
2206        LineNo: c_uint,
2207        Ty: &'a DIType,
2208        Flags: DIFlags,
2209        val: Option<&'a Value>,
2210        AlignInBits: u32,
2211    ) -> &'a DIDerivedType;
2212
2213    pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>(
2214        Builder: &DIBuilder<'a>,
2215        Tag: c_uint,
2216        Type: &'a DIType,
2217    ) -> &'a DIDerivedType;
2218
2219    pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>(
2220        Builder: &DIBuilder<'a>,
2221        Context: Option<&'a DIScope>,
2222        Name: *const c_char,
2223        NameLen: size_t,
2224        LinkageName: *const c_char,
2225        LinkageNameLen: size_t,
2226        File: &'a DIFile,
2227        LineNo: c_uint,
2228        Ty: &'a DIType,
2229        isLocalToUnit: bool,
2230        Val: &'a Value,
2231        Decl: Option<&'a DIDescriptor>,
2232        AlignInBits: u32,
2233    ) -> &'a DIGlobalVariableExpression;
2234
2235    pub(crate) fn LLVMRustDIBuilderCreateVariable<'a>(
2236        Builder: &DIBuilder<'a>,
2237        Tag: c_uint,
2238        Scope: &'a DIDescriptor,
2239        Name: *const c_char,
2240        NameLen: size_t,
2241        File: &'a DIFile,
2242        LineNo: c_uint,
2243        Ty: &'a DIType,
2244        AlwaysPreserve: bool,
2245        Flags: DIFlags,
2246        ArgNo: c_uint,
2247        AlignInBits: u32,
2248    ) -> &'a DIVariable;
2249
2250    pub(crate) fn LLVMRustDIBuilderCreateArrayType<'a>(
2251        Builder: &DIBuilder<'a>,
2252        Size: u64,
2253        AlignInBits: u32,
2254        Ty: &'a DIType,
2255        Subscripts: &'a DIArray,
2256    ) -> &'a DIType;
2257
2258    pub(crate) fn LLVMRustDIBuilderGetOrCreateSubrange<'a>(
2259        Builder: &DIBuilder<'a>,
2260        Lo: i64,
2261        Count: i64,
2262    ) -> &'a DISubrange;
2263
2264    pub(crate) fn LLVMRustDIBuilderGetOrCreateArray<'a>(
2265        Builder: &DIBuilder<'a>,
2266        Ptr: *const Option<&'a DIDescriptor>,
2267        Count: c_uint,
2268    ) -> &'a DIArray;
2269
2270    pub(crate) fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>(
2271        Builder: &DIBuilder<'a>,
2272        Val: &'a Value,
2273        VarInfo: &'a DIVariable,
2274        AddrOps: *const u64,
2275        AddrOpsCount: c_uint,
2276        DL: &'a DILocation,
2277        InsertAtEnd: &'a BasicBlock,
2278    );
2279
2280    pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>(
2281        Builder: &DIBuilder<'a>,
2282        Name: *const c_char,
2283        NameLen: size_t,
2284        Value: *const u64,
2285        SizeInBits: c_uint,
2286        IsUnsigned: bool,
2287    ) -> &'a DIEnumerator;
2288
2289    pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>(
2290        Builder: &DIBuilder<'a>,
2291        Scope: &'a DIScope,
2292        Name: *const c_char,
2293        NameLen: size_t,
2294        File: &'a DIFile,
2295        LineNumber: c_uint,
2296        SizeInBits: u64,
2297        AlignInBits: u32,
2298        Elements: &'a DIArray,
2299        ClassType: &'a DIType,
2300        IsScoped: bool,
2301    ) -> &'a DIType;
2302
2303    pub(crate) fn LLVMRustDIBuilderCreateUnionType<'a>(
2304        Builder: &DIBuilder<'a>,
2305        Scope: Option<&'a DIScope>,
2306        Name: *const c_char,
2307        NameLen: size_t,
2308        File: &'a DIFile,
2309        LineNumber: c_uint,
2310        SizeInBits: u64,
2311        AlignInBits: u32,
2312        Flags: DIFlags,
2313        Elements: Option<&'a DIArray>,
2314        RunTimeLang: c_uint,
2315        UniqueId: *const c_char,
2316        UniqueIdLen: size_t,
2317    ) -> &'a DIType;
2318
2319    pub(crate) fn LLVMRustDIBuilderCreateVariantPart<'a>(
2320        Builder: &DIBuilder<'a>,
2321        Scope: &'a DIScope,
2322        Name: *const c_char,
2323        NameLen: size_t,
2324        File: &'a DIFile,
2325        LineNo: c_uint,
2326        SizeInBits: u64,
2327        AlignInBits: u32,
2328        Flags: DIFlags,
2329        Discriminator: Option<&'a DIDerivedType>,
2330        Elements: &'a DIArray,
2331        UniqueId: *const c_char,
2332        UniqueIdLen: size_t,
2333    ) -> &'a DIDerivedType;
2334
2335    pub(crate) fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
2336        Builder: &DIBuilder<'a>,
2337        Scope: Option<&'a DIScope>,
2338        Name: *const c_char,
2339        NameLen: size_t,
2340        Ty: &'a DIType,
2341    ) -> &'a DITemplateTypeParameter;
2342
2343    pub(crate) fn LLVMRustDICompositeTypeReplaceArrays<'a>(
2344        Builder: &DIBuilder<'a>,
2345        CompositeType: &'a DIType,
2346        Elements: Option<&'a DIArray>,
2347        Params: Option<&'a DIArray>,
2348    );
2349
2350    pub(crate) fn LLVMRustDILocationCloneWithBaseDiscriminator<'a>(
2351        Location: &'a DILocation,
2352        BD: c_uint,
2353    ) -> Option<&'a DILocation>;
2354
2355    pub(crate) fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
2356    pub(crate) fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
2357
2358    pub(crate) fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
2359
2360    pub(crate) fn LLVMRustPrintTargetCPUs(TM: &TargetMachine, OutStr: &RustString);
2361    pub(crate) fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;
2362    pub(crate) fn LLVMRustGetTargetFeature(
2363        T: &TargetMachine,
2364        Index: size_t,
2365        Feature: &mut *const c_char,
2366        Desc: &mut *const c_char,
2367    );
2368
2369    pub(crate) fn LLVMRustGetHostCPUName(LenOut: &mut size_t) -> *const u8;
2370
2371    // This function makes copies of pointed to data, so the data's lifetime may end after this
2372    // function returns.
2373    pub(crate) fn LLVMRustCreateTargetMachine(
2374        Triple: *const c_char,
2375        CPU: *const c_char,
2376        Features: *const c_char,
2377        Abi: *const c_char,
2378        Model: CodeModel,
2379        Reloc: RelocModel,
2380        Level: CodeGenOptLevel,
2381        FloatABIType: FloatAbi,
2382        FunctionSections: bool,
2383        DataSections: bool,
2384        UniqueSectionNames: bool,
2385        TrapUnreachable: bool,
2386        Singlethread: bool,
2387        VerboseAsm: bool,
2388        EmitStackSizeSection: bool,
2389        RelaxELFRelocations: bool,
2390        UseInitArray: bool,
2391        SplitDwarfFile: *const c_char,
2392        OutputObjFile: *const c_char,
2393        DebugInfoCompression: *const c_char,
2394        UseEmulatedTls: bool,
2395        ArgsCstrBuff: *const c_char,
2396        ArgsCstrBuffLen: usize,
2397    ) -> *mut TargetMachine;
2398
2399    pub(crate) fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine);
2400    pub(crate) fn LLVMRustAddLibraryInfo<'a>(
2401        PM: &PassManager<'a>,
2402        M: &'a Module,
2403        DisableSimplifyLibCalls: bool,
2404    );
2405    pub(crate) fn LLVMRustWriteOutputFile<'a>(
2406        T: &'a TargetMachine,
2407        PM: *mut PassManager<'a>,
2408        M: &'a Module,
2409        Output: *const c_char,
2410        DwoOutput: *const c_char,
2411        FileType: FileType,
2412        VerifyIR: bool,
2413    ) -> LLVMRustResult;
2414    pub(crate) fn LLVMRustOptimize<'a>(
2415        M: &'a Module,
2416        TM: &'a TargetMachine,
2417        OptLevel: PassBuilderOptLevel,
2418        OptStage: OptStage,
2419        IsLinkerPluginLTO: bool,
2420        NoPrepopulatePasses: bool,
2421        VerifyIR: bool,
2422        LintIR: bool,
2423        UseThinLTOBuffers: bool,
2424        MergeFunctions: bool,
2425        UnrollLoops: bool,
2426        SLPVectorize: bool,
2427        LoopVectorize: bool,
2428        DisableSimplifyLibCalls: bool,
2429        EmitLifetimeMarkers: bool,
2430        RunEnzyme: bool,
2431        SanitizerOptions: Option<&SanitizerOptions>,
2432        PGOGenPath: *const c_char,
2433        PGOUsePath: *const c_char,
2434        InstrumentCoverage: bool,
2435        InstrProfileOutput: *const c_char,
2436        PGOSampleUsePath: *const c_char,
2437        DebugInfoForProfiling: bool,
2438        llvm_selfprofiler: *mut c_void,
2439        begin_callback: SelfProfileBeforePassCallback,
2440        end_callback: SelfProfileAfterPassCallback,
2441        ExtraPasses: *const c_char,
2442        ExtraPassesLen: size_t,
2443        LLVMPlugins: *const c_char,
2444        LLVMPluginsLen: size_t,
2445    ) -> LLVMRustResult;
2446    pub(crate) fn LLVMRustPrintModule(
2447        M: &Module,
2448        Output: *const c_char,
2449        Demangle: extern "C" fn(*const c_char, size_t, *mut c_char, size_t) -> size_t,
2450    ) -> LLVMRustResult;
2451    pub(crate) fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2452    pub(crate) fn LLVMRustPrintPasses();
2453    pub(crate) fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
2454    pub(crate) fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
2455
2456    pub(crate) fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
2457    pub(crate) fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
2458    pub(crate) fn LLVMRustArchiveIteratorNext<'a>(
2459        AIR: &ArchiveIterator<'a>,
2460    ) -> Option<&'a mut ArchiveChild<'a>>;
2461    pub(crate) fn LLVMRustArchiveChildName(
2462        ACR: &ArchiveChild<'_>,
2463        size: &mut size_t,
2464    ) -> *const c_char;
2465    pub(crate) fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>);
2466    pub(crate) fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>);
2467    pub(crate) fn LLVMRustDestroyArchive(AR: &'static mut Archive);
2468
2469    pub(crate) fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
2470
2471    pub(crate) fn LLVMRustUnpackOptimizationDiagnostic<'a>(
2472        DI: &'a DiagnosticInfo,
2473        pass_name_out: &RustString,
2474        function_out: &mut Option<&'a Value>,
2475        loc_line_out: &mut c_uint,
2476        loc_column_out: &mut c_uint,
2477        loc_filename_out: &RustString,
2478        message_out: &RustString,
2479    );
2480
2481    pub(crate) fn LLVMRustUnpackInlineAsmDiagnostic<'a>(
2482        DI: &'a DiagnosticInfo,
2483        level_out: &mut DiagnosticLevel,
2484        cookie_out: &mut u64,
2485        message_out: &mut Option<&'a Twine>,
2486    );
2487
2488    pub(crate) fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
2489    pub(crate) fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
2490
2491    pub(crate) fn LLVMRustGetSMDiagnostic<'a>(
2492        DI: &'a DiagnosticInfo,
2493        cookie_out: &mut u64,
2494    ) -> &'a SMDiagnostic;
2495
2496    pub(crate) fn LLVMRustUnpackSMDiagnostic(
2497        d: &SMDiagnostic,
2498        message_out: &RustString,
2499        buffer_out: &RustString,
2500        level_out: &mut DiagnosticLevel,
2501        loc_out: &mut c_uint,
2502        ranges_out: *mut c_uint,
2503        num_ranges: &mut usize,
2504    ) -> bool;
2505
2506    pub(crate) fn LLVMRustWriteArchive(
2507        Dst: *const c_char,
2508        NumMembers: size_t,
2509        Members: *const &RustArchiveMember<'_>,
2510        WriteSymbtab: bool,
2511        Kind: ArchiveKind,
2512        isEC: bool,
2513    ) -> LLVMRustResult;
2514    pub(crate) fn LLVMRustArchiveMemberNew<'a>(
2515        Filename: *const c_char,
2516        Name: *const c_char,
2517        Child: Option<&ArchiveChild<'a>>,
2518    ) -> &'a mut RustArchiveMember<'a>;
2519    pub(crate) fn LLVMRustArchiveMemberFree<'a>(Member: &'a mut RustArchiveMember<'a>);
2520
2521    pub(crate) fn LLVMRustSetDataLayoutFromTargetMachine<'a>(M: &'a Module, TM: &'a TargetMachine);
2522
2523    pub(crate) fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock);
2524
2525    pub(crate) fn LLVMRustSetModulePICLevel(M: &Module);
2526    pub(crate) fn LLVMRustSetModulePIELevel(M: &Module);
2527    pub(crate) fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);
2528    pub(crate) fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
2529    pub(crate) fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
2530    pub(crate) fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
2531    pub(crate) fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
2532    pub(crate) fn LLVMRustModuleCost(M: &Module) -> u64;
2533    pub(crate) fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
2534
2535    pub(crate) fn LLVMRustThinLTOBufferCreate(
2536        M: &Module,
2537        is_thin: bool,
2538        emit_summary: bool,
2539    ) -> &'static mut ThinLTOBuffer;
2540    pub(crate) fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
2541    pub(crate) fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
2542    pub(crate) fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2543    pub(crate) fn LLVMRustThinLTOBufferThinLinkDataPtr(M: &ThinLTOBuffer) -> *const c_char;
2544    pub(crate) fn LLVMRustThinLTOBufferThinLinkDataLen(M: &ThinLTOBuffer) -> size_t;
2545    pub(crate) fn LLVMRustCreateThinLTOData(
2546        Modules: *const ThinLTOModule,
2547        NumModules: size_t,
2548        PreservedSymbols: *const *const c_char,
2549        PreservedSymbolsLen: size_t,
2550    ) -> Option<&'static mut ThinLTOData>;
2551    pub(crate) fn LLVMRustPrepareThinLTORename(
2552        Data: &ThinLTOData,
2553        Module: &Module,
2554        Target: &TargetMachine,
2555    );
2556    pub(crate) fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool;
2557    pub(crate) fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool;
2558    pub(crate) fn LLVMRustPrepareThinLTOImport(
2559        Data: &ThinLTOData,
2560        Module: &Module,
2561        Target: &TargetMachine,
2562    ) -> bool;
2563    pub(crate) fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
2564    pub(crate) fn LLVMRustParseBitcodeForLTO(
2565        Context: &Context,
2566        Data: *const u8,
2567        len: usize,
2568        Identifier: *const c_char,
2569    ) -> Option<&Module>;
2570    pub(crate) fn LLVMRustGetSliceFromObjectDataByName(
2571        data: *const u8,
2572        len: usize,
2573        name: *const u8,
2574        name_len: usize,
2575        out_len: &mut usize,
2576    ) -> *const u8;
2577
2578    pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
2579    pub(crate) fn LLVMRustLinkerAdd(
2580        linker: &Linker<'_>,
2581        bytecode: *const c_char,
2582        bytecode_len: usize,
2583    ) -> bool;
2584    pub(crate) fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>);
2585    pub(crate) fn LLVMRustComputeLTOCacheKey(
2586        key_out: &RustString,
2587        mod_id: *const c_char,
2588        data: &ThinLTOData,
2589    );
2590
2591    pub(crate) fn LLVMRustContextGetDiagnosticHandler(
2592        Context: &Context,
2593    ) -> Option<&DiagnosticHandler>;
2594    pub(crate) fn LLVMRustContextSetDiagnosticHandler(
2595        context: &Context,
2596        diagnostic_handler: Option<&DiagnosticHandler>,
2597    );
2598    pub(crate) fn LLVMRustContextConfigureDiagnosticHandler(
2599        context: &Context,
2600        diagnostic_handler_callback: DiagnosticHandlerTy,
2601        diagnostic_handler_context: *mut c_void,
2602        remark_all_passes: bool,
2603        remark_passes: *const *const c_char,
2604        remark_passes_len: usize,
2605        remark_file: *const c_char,
2606        pgo_available: bool,
2607    );
2608
2609    pub(crate) fn LLVMRustGetMangledName(V: &Value, out: &RustString);
2610
2611    pub(crate) fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32;
2612
2613    pub(crate) fn LLVMRustLLVMHasZlibCompressionForDebugSymbols() -> bool;
2614
2615    pub(crate) fn LLVMRustLLVMHasZstdCompressionForDebugSymbols() -> bool;
2616
2617    pub(crate) fn LLVMRustGetSymbols(
2618        buf_ptr: *const u8,
2619        buf_len: usize,
2620        state: *mut c_void,
2621        callback: GetSymbolsCallback,
2622        error_callback: GetSymbolsErrorCallback,
2623    ) -> *mut c_void;
2624
2625    pub(crate) fn LLVMRustIs64BitSymbolicFile(buf_ptr: *const u8, buf_len: usize) -> bool;
2626
2627    pub(crate) fn LLVMRustIsECObject(buf_ptr: *const u8, buf_len: usize) -> bool;
2628
2629    pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value);
2630    pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value);
2631}