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