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