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