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