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