]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/llvm/ffi.rs
Rollup merge of #68984 - ecstatic-morse:const-u8-is-ascii, r=sfackler
[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: syntax::ast::AsmDialect) -> Self {
385         match asm {
386             syntax::ast::AsmDialect::Att => AsmDialect::Att,
387             syntax::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);
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(M: &Module, Name: *const c_char) -> Option<&Value>;
883     pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
884
885     // Operations on functions
886     pub fn LLVMRustGetOrInsertFunction(
887         M: &'a Module,
888         Name: *const c_char,
889         FunctionTy: &'a Type,
890     ) -> &'a Value;
891     pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
892     pub fn LLVMRustAddAlignmentAttr(Fn: &Value, index: c_uint, bytes: u32);
893     pub fn LLVMRustAddDereferenceableAttr(Fn: &Value, index: c_uint, bytes: u64);
894     pub fn LLVMRustAddDereferenceableOrNullAttr(Fn: &Value, index: c_uint, bytes: u64);
895     pub fn LLVMRustAddByValAttr(Fn: &Value, index: c_uint, ty: &Type);
896     pub fn LLVMRustAddFunctionAttribute(Fn: &Value, index: c_uint, attr: Attribute);
897     pub fn LLVMRustAddFunctionAttrStringValue(
898         Fn: &Value,
899         index: c_uint,
900         Name: *const c_char,
901         Value: *const c_char,
902     );
903     pub fn LLVMRustRemoveFunctionAttributes(Fn: &Value, index: c_uint, attr: Attribute);
904
905     // Operations on parameters
906     pub fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
907     pub fn LLVMCountParams(Fn: &Value) -> c_uint;
908     pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
909
910     // Operations on basic blocks
911     pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
912     pub fn LLVMAppendBasicBlockInContext(
913         C: &'a Context,
914         Fn: &'a Value,
915         Name: *const c_char,
916     ) -> &'a BasicBlock;
917     pub fn LLVMDeleteBasicBlock(BB: &BasicBlock);
918
919     // Operations on instructions
920     pub fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
921     pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
922
923     // Operations on call sites
924     pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
925     pub fn LLVMRustAddCallSiteAttribute(Instr: &Value, index: c_uint, attr: Attribute);
926     pub fn LLVMRustAddAlignmentCallSiteAttr(Instr: &Value, index: c_uint, bytes: u32);
927     pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
928     pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
929     pub fn LLVMRustAddByValCallSiteAttr(Instr: &Value, index: c_uint, ty: &Type);
930
931     // Operations on load/store instructions (only)
932     pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
933
934     // Operations on phi nodes
935     pub fn LLVMAddIncoming(
936         PhiNode: &'a Value,
937         IncomingValues: *const &'a Value,
938         IncomingBlocks: *const &'a BasicBlock,
939         Count: c_uint,
940     );
941
942     // Instruction builders
943     pub fn LLVMCreateBuilderInContext(C: &'a Context) -> &'a mut Builder<'a>;
944     pub fn LLVMPositionBuilderAtEnd(Builder: &Builder<'a>, Block: &'a BasicBlock);
945     pub fn LLVMGetInsertBlock(Builder: &Builder<'a>) -> &'a BasicBlock;
946     pub fn LLVMDisposeBuilder(Builder: &'a mut Builder<'a>);
947
948     // Metadata
949     pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: &'a Value);
950
951     // Terminators
952     pub fn LLVMBuildRetVoid(B: &Builder<'a>) -> &'a Value;
953     pub fn LLVMBuildRet(B: &Builder<'a>, V: &'a Value) -> &'a Value;
954     pub fn LLVMBuildBr(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
955     pub fn LLVMBuildCondBr(
956         B: &Builder<'a>,
957         If: &'a Value,
958         Then: &'a BasicBlock,
959         Else: &'a BasicBlock,
960     ) -> &'a Value;
961     pub fn LLVMBuildSwitch(
962         B: &Builder<'a>,
963         V: &'a Value,
964         Else: &'a BasicBlock,
965         NumCases: c_uint,
966     ) -> &'a Value;
967     pub fn LLVMRustBuildInvoke(
968         B: &Builder<'a>,
969         Fn: &'a Value,
970         Args: *const &'a Value,
971         NumArgs: c_uint,
972         Then: &'a BasicBlock,
973         Catch: &'a BasicBlock,
974         Bundle: Option<&OperandBundleDef<'a>>,
975         Name: *const c_char,
976     ) -> &'a Value;
977     pub fn LLVMBuildLandingPad(
978         B: &Builder<'a>,
979         Ty: &'a Type,
980         PersFn: &'a Value,
981         NumClauses: c_uint,
982         Name: *const c_char,
983     ) -> &'a Value;
984     pub fn LLVMBuildResume(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
985     pub fn LLVMBuildUnreachable(B: &Builder<'a>) -> &'a Value;
986
987     pub fn LLVMRustBuildCleanupPad(
988         B: &Builder<'a>,
989         ParentPad: Option<&'a Value>,
990         ArgCnt: c_uint,
991         Args: *const &'a Value,
992         Name: *const c_char,
993     ) -> Option<&'a Value>;
994     pub fn LLVMRustBuildCleanupRet(
995         B: &Builder<'a>,
996         CleanupPad: &'a Value,
997         UnwindBB: Option<&'a BasicBlock>,
998     ) -> Option<&'a Value>;
999     pub fn LLVMRustBuildCatchPad(
1000         B: &Builder<'a>,
1001         ParentPad: &'a Value,
1002         ArgCnt: c_uint,
1003         Args: *const &'a Value,
1004         Name: *const c_char,
1005     ) -> Option<&'a Value>;
1006     pub fn LLVMRustBuildCatchRet(
1007         B: &Builder<'a>,
1008         Pad: &'a Value,
1009         BB: &'a BasicBlock,
1010     ) -> Option<&'a Value>;
1011     pub fn LLVMRustBuildCatchSwitch(
1012         Builder: &Builder<'a>,
1013         ParentPad: Option<&'a Value>,
1014         BB: Option<&'a BasicBlock>,
1015         NumHandlers: c_uint,
1016         Name: *const c_char,
1017     ) -> Option<&'a Value>;
1018     pub fn LLVMRustAddHandler(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
1019     pub fn LLVMSetPersonalityFn(Func: &'a Value, Pers: &'a Value);
1020
1021     // Add a case to the switch instruction
1022     pub fn LLVMAddCase(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
1023
1024     // Add a clause to the landing pad instruction
1025     pub fn LLVMAddClause(LandingPad: &'a Value, ClauseVal: &'a Value);
1026
1027     // Set the cleanup on a landing pad instruction
1028     pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
1029
1030     // Arithmetic
1031     pub fn LLVMBuildAdd(
1032         B: &Builder<'a>,
1033         LHS: &'a Value,
1034         RHS: &'a Value,
1035         Name: *const c_char,
1036     ) -> &'a Value;
1037     pub fn LLVMBuildFAdd(
1038         B: &Builder<'a>,
1039         LHS: &'a Value,
1040         RHS: &'a Value,
1041         Name: *const c_char,
1042     ) -> &'a Value;
1043     pub fn LLVMBuildSub(
1044         B: &Builder<'a>,
1045         LHS: &'a Value,
1046         RHS: &'a Value,
1047         Name: *const c_char,
1048     ) -> &'a Value;
1049     pub fn LLVMBuildFSub(
1050         B: &Builder<'a>,
1051         LHS: &'a Value,
1052         RHS: &'a Value,
1053         Name: *const c_char,
1054     ) -> &'a Value;
1055     pub fn LLVMBuildMul(
1056         B: &Builder<'a>,
1057         LHS: &'a Value,
1058         RHS: &'a Value,
1059         Name: *const c_char,
1060     ) -> &'a Value;
1061     pub fn LLVMBuildFMul(
1062         B: &Builder<'a>,
1063         LHS: &'a Value,
1064         RHS: &'a Value,
1065         Name: *const c_char,
1066     ) -> &'a Value;
1067     pub fn LLVMBuildUDiv(
1068         B: &Builder<'a>,
1069         LHS: &'a Value,
1070         RHS: &'a Value,
1071         Name: *const c_char,
1072     ) -> &'a Value;
1073     pub fn LLVMBuildExactUDiv(
1074         B: &Builder<'a>,
1075         LHS: &'a Value,
1076         RHS: &'a Value,
1077         Name: *const c_char,
1078     ) -> &'a Value;
1079     pub fn LLVMBuildSDiv(
1080         B: &Builder<'a>,
1081         LHS: &'a Value,
1082         RHS: &'a Value,
1083         Name: *const c_char,
1084     ) -> &'a Value;
1085     pub fn LLVMBuildExactSDiv(
1086         B: &Builder<'a>,
1087         LHS: &'a Value,
1088         RHS: &'a Value,
1089         Name: *const c_char,
1090     ) -> &'a Value;
1091     pub fn LLVMBuildFDiv(
1092         B: &Builder<'a>,
1093         LHS: &'a Value,
1094         RHS: &'a Value,
1095         Name: *const c_char,
1096     ) -> &'a Value;
1097     pub fn LLVMBuildURem(
1098         B: &Builder<'a>,
1099         LHS: &'a Value,
1100         RHS: &'a Value,
1101         Name: *const c_char,
1102     ) -> &'a Value;
1103     pub fn LLVMBuildSRem(
1104         B: &Builder<'a>,
1105         LHS: &'a Value,
1106         RHS: &'a Value,
1107         Name: *const c_char,
1108     ) -> &'a Value;
1109     pub fn LLVMBuildFRem(
1110         B: &Builder<'a>,
1111         LHS: &'a Value,
1112         RHS: &'a Value,
1113         Name: *const c_char,
1114     ) -> &'a Value;
1115     pub fn LLVMBuildShl(
1116         B: &Builder<'a>,
1117         LHS: &'a Value,
1118         RHS: &'a Value,
1119         Name: *const c_char,
1120     ) -> &'a Value;
1121     pub fn LLVMBuildLShr(
1122         B: &Builder<'a>,
1123         LHS: &'a Value,
1124         RHS: &'a Value,
1125         Name: *const c_char,
1126     ) -> &'a Value;
1127     pub fn LLVMBuildAShr(
1128         B: &Builder<'a>,
1129         LHS: &'a Value,
1130         RHS: &'a Value,
1131         Name: *const c_char,
1132     ) -> &'a Value;
1133     pub fn LLVMBuildNSWAdd(
1134         B: &Builder<'a>,
1135         LHS: &'a Value,
1136         RHS: &'a Value,
1137         Name: *const c_char,
1138     ) -> &'a Value;
1139     pub fn LLVMBuildNUWAdd(
1140         B: &Builder<'a>,
1141         LHS: &'a Value,
1142         RHS: &'a Value,
1143         Name: *const c_char,
1144     ) -> &'a Value;
1145     pub fn LLVMBuildNSWSub(
1146         B: &Builder<'a>,
1147         LHS: &'a Value,
1148         RHS: &'a Value,
1149         Name: *const c_char,
1150     ) -> &'a Value;
1151     pub fn LLVMBuildNUWSub(
1152         B: &Builder<'a>,
1153         LHS: &'a Value,
1154         RHS: &'a Value,
1155         Name: *const c_char,
1156     ) -> &'a Value;
1157     pub fn LLVMBuildNSWMul(
1158         B: &Builder<'a>,
1159         LHS: &'a Value,
1160         RHS: &'a Value,
1161         Name: *const c_char,
1162     ) -> &'a Value;
1163     pub fn LLVMBuildNUWMul(
1164         B: &Builder<'a>,
1165         LHS: &'a Value,
1166         RHS: &'a Value,
1167         Name: *const c_char,
1168     ) -> &'a Value;
1169     pub fn LLVMBuildAnd(
1170         B: &Builder<'a>,
1171         LHS: &'a Value,
1172         RHS: &'a Value,
1173         Name: *const c_char,
1174     ) -> &'a Value;
1175     pub fn LLVMBuildOr(
1176         B: &Builder<'a>,
1177         LHS: &'a Value,
1178         RHS: &'a Value,
1179         Name: *const c_char,
1180     ) -> &'a Value;
1181     pub fn LLVMBuildXor(
1182         B: &Builder<'a>,
1183         LHS: &'a Value,
1184         RHS: &'a Value,
1185         Name: *const c_char,
1186     ) -> &'a Value;
1187     pub fn LLVMBuildNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1188     pub fn LLVMBuildFNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1189     pub fn LLVMBuildNot(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1190     pub fn LLVMRustSetHasUnsafeAlgebra(Instr: &Value);
1191
1192     // Memory
1193     pub fn LLVMBuildAlloca(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1194     pub fn LLVMBuildArrayAlloca(
1195         B: &Builder<'a>,
1196         Ty: &'a Type,
1197         Val: &'a Value,
1198         Name: *const c_char,
1199     ) -> &'a Value;
1200     pub fn LLVMBuildLoad(B: &Builder<'a>, PointerVal: &'a Value, Name: *const c_char) -> &'a Value;
1201
1202     pub fn LLVMBuildStore(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
1203
1204     pub fn LLVMBuildGEP(
1205         B: &Builder<'a>,
1206         Pointer: &'a Value,
1207         Indices: *const &'a Value,
1208         NumIndices: c_uint,
1209         Name: *const c_char,
1210     ) -> &'a Value;
1211     pub fn LLVMBuildInBoundsGEP(
1212         B: &Builder<'a>,
1213         Pointer: &'a Value,
1214         Indices: *const &'a Value,
1215         NumIndices: c_uint,
1216         Name: *const c_char,
1217     ) -> &'a Value;
1218     pub fn LLVMBuildStructGEP(
1219         B: &Builder<'a>,
1220         Pointer: &'a Value,
1221         Idx: c_uint,
1222         Name: *const c_char,
1223     ) -> &'a Value;
1224
1225     // Casts
1226     pub fn LLVMBuildTrunc(
1227         B: &Builder<'a>,
1228         Val: &'a Value,
1229         DestTy: &'a Type,
1230         Name: *const c_char,
1231     ) -> &'a Value;
1232     pub fn LLVMBuildZExt(
1233         B: &Builder<'a>,
1234         Val: &'a Value,
1235         DestTy: &'a Type,
1236         Name: *const c_char,
1237     ) -> &'a Value;
1238     pub fn LLVMBuildSExt(
1239         B: &Builder<'a>,
1240         Val: &'a Value,
1241         DestTy: &'a Type,
1242         Name: *const c_char,
1243     ) -> &'a Value;
1244     pub fn LLVMBuildFPToUI(
1245         B: &Builder<'a>,
1246         Val: &'a Value,
1247         DestTy: &'a Type,
1248         Name: *const c_char,
1249     ) -> &'a Value;
1250     pub fn LLVMBuildFPToSI(
1251         B: &Builder<'a>,
1252         Val: &'a Value,
1253         DestTy: &'a Type,
1254         Name: *const c_char,
1255     ) -> &'a Value;
1256     pub fn LLVMBuildUIToFP(
1257         B: &Builder<'a>,
1258         Val: &'a Value,
1259         DestTy: &'a Type,
1260         Name: *const c_char,
1261     ) -> &'a Value;
1262     pub fn LLVMBuildSIToFP(
1263         B: &Builder<'a>,
1264         Val: &'a Value,
1265         DestTy: &'a Type,
1266         Name: *const c_char,
1267     ) -> &'a Value;
1268     pub fn LLVMBuildFPTrunc(
1269         B: &Builder<'a>,
1270         Val: &'a Value,
1271         DestTy: &'a Type,
1272         Name: *const c_char,
1273     ) -> &'a Value;
1274     pub fn LLVMBuildFPExt(
1275         B: &Builder<'a>,
1276         Val: &'a Value,
1277         DestTy: &'a Type,
1278         Name: *const c_char,
1279     ) -> &'a Value;
1280     pub fn LLVMBuildPtrToInt(
1281         B: &Builder<'a>,
1282         Val: &'a Value,
1283         DestTy: &'a Type,
1284         Name: *const c_char,
1285     ) -> &'a Value;
1286     pub fn LLVMBuildIntToPtr(
1287         B: &Builder<'a>,
1288         Val: &'a Value,
1289         DestTy: &'a Type,
1290         Name: *const c_char,
1291     ) -> &'a Value;
1292     pub fn LLVMBuildBitCast(
1293         B: &Builder<'a>,
1294         Val: &'a Value,
1295         DestTy: &'a Type,
1296         Name: *const c_char,
1297     ) -> &'a Value;
1298     pub fn LLVMBuildPointerCast(
1299         B: &Builder<'a>,
1300         Val: &'a Value,
1301         DestTy: &'a Type,
1302         Name: *const c_char,
1303     ) -> &'a Value;
1304     pub fn LLVMRustBuildIntCast(
1305         B: &Builder<'a>,
1306         Val: &'a Value,
1307         DestTy: &'a Type,
1308         IsSized: bool,
1309     ) -> &'a Value;
1310
1311     // Comparisons
1312     pub fn LLVMBuildICmp(
1313         B: &Builder<'a>,
1314         Op: c_uint,
1315         LHS: &'a Value,
1316         RHS: &'a Value,
1317         Name: *const c_char,
1318     ) -> &'a Value;
1319     pub fn LLVMBuildFCmp(
1320         B: &Builder<'a>,
1321         Op: c_uint,
1322         LHS: &'a Value,
1323         RHS: &'a Value,
1324         Name: *const c_char,
1325     ) -> &'a Value;
1326
1327     // Miscellaneous instructions
1328     pub fn LLVMBuildPhi(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1329     pub fn LLVMRustBuildCall(
1330         B: &Builder<'a>,
1331         Fn: &'a Value,
1332         Args: *const &'a Value,
1333         NumArgs: c_uint,
1334         Bundle: Option<&OperandBundleDef<'a>>,
1335         Name: *const c_char,
1336     ) -> &'a Value;
1337     pub fn LLVMRustBuildMemCpy(
1338         B: &Builder<'a>,
1339         Dst: &'a Value,
1340         DstAlign: c_uint,
1341         Src: &'a Value,
1342         SrcAlign: c_uint,
1343         Size: &'a Value,
1344         IsVolatile: bool,
1345     ) -> &'a Value;
1346     pub fn LLVMRustBuildMemMove(
1347         B: &Builder<'a>,
1348         Dst: &'a Value,
1349         DstAlign: c_uint,
1350         Src: &'a Value,
1351         SrcAlign: c_uint,
1352         Size: &'a Value,
1353         IsVolatile: bool,
1354     ) -> &'a Value;
1355     pub fn LLVMRustBuildMemSet(
1356         B: &Builder<'a>,
1357         Dst: &'a Value,
1358         DstAlign: c_uint,
1359         Val: &'a Value,
1360         Size: &'a Value,
1361         IsVolatile: bool,
1362     ) -> &'a Value;
1363     pub fn LLVMBuildSelect(
1364         B: &Builder<'a>,
1365         If: &'a Value,
1366         Then: &'a Value,
1367         Else: &'a Value,
1368         Name: *const c_char,
1369     ) -> &'a Value;
1370     pub fn LLVMBuildVAArg(
1371         B: &Builder<'a>,
1372         list: &'a Value,
1373         Ty: &'a Type,
1374         Name: *const c_char,
1375     ) -> &'a Value;
1376     pub fn LLVMBuildExtractElement(
1377         B: &Builder<'a>,
1378         VecVal: &'a Value,
1379         Index: &'a Value,
1380         Name: *const c_char,
1381     ) -> &'a Value;
1382     pub fn LLVMBuildInsertElement(
1383         B: &Builder<'a>,
1384         VecVal: &'a Value,
1385         EltVal: &'a Value,
1386         Index: &'a Value,
1387         Name: *const c_char,
1388     ) -> &'a Value;
1389     pub fn LLVMBuildShuffleVector(
1390         B: &Builder<'a>,
1391         V1: &'a Value,
1392         V2: &'a Value,
1393         Mask: &'a Value,
1394         Name: *const c_char,
1395     ) -> &'a Value;
1396     pub fn LLVMBuildExtractValue(
1397         B: &Builder<'a>,
1398         AggVal: &'a Value,
1399         Index: c_uint,
1400         Name: *const c_char,
1401     ) -> &'a Value;
1402     pub fn LLVMBuildInsertValue(
1403         B: &Builder<'a>,
1404         AggVal: &'a Value,
1405         EltVal: &'a Value,
1406         Index: c_uint,
1407         Name: *const c_char,
1408     ) -> &'a Value;
1409
1410     pub fn LLVMRustBuildVectorReduceFAdd(
1411         B: &Builder<'a>,
1412         Acc: &'a Value,
1413         Src: &'a Value,
1414     ) -> &'a Value;
1415     pub fn LLVMRustBuildVectorReduceFMul(
1416         B: &Builder<'a>,
1417         Acc: &'a Value,
1418         Src: &'a Value,
1419     ) -> &'a Value;
1420     pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1421     pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1422     pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1423     pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1424     pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1425     pub fn LLVMRustBuildVectorReduceMin(
1426         B: &Builder<'a>,
1427         Src: &'a Value,
1428         IsSigned: bool,
1429     ) -> &'a Value;
1430     pub fn LLVMRustBuildVectorReduceMax(
1431         B: &Builder<'a>,
1432         Src: &'a Value,
1433         IsSigned: bool,
1434     ) -> &'a Value;
1435     pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>, Src: &'a Value, IsNaN: bool)
1436     -> &'a Value;
1437     pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>, Src: &'a Value, IsNaN: bool)
1438     -> &'a Value;
1439
1440     pub fn LLVMRustBuildMinNum(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
1441     pub fn LLVMRustBuildMaxNum(B: &Builder<'a>, LHS: &'a Value, LHS: &'a Value) -> &'a Value;
1442
1443     // Atomic Operations
1444     pub fn LLVMRustBuildAtomicLoad(
1445         B: &Builder<'a>,
1446         PointerVal: &'a Value,
1447         Name: *const c_char,
1448         Order: AtomicOrdering,
1449     ) -> &'a Value;
1450
1451     pub fn LLVMRustBuildAtomicStore(
1452         B: &Builder<'a>,
1453         Val: &'a Value,
1454         Ptr: &'a Value,
1455         Order: AtomicOrdering,
1456     ) -> &'a Value;
1457
1458     pub fn LLVMRustBuildAtomicCmpXchg(
1459         B: &Builder<'a>,
1460         LHS: &'a Value,
1461         CMP: &'a Value,
1462         RHS: &'a Value,
1463         Order: AtomicOrdering,
1464         FailureOrder: AtomicOrdering,
1465         Weak: Bool,
1466     ) -> &'a Value;
1467
1468     pub fn LLVMBuildAtomicRMW(
1469         B: &Builder<'a>,
1470         Op: AtomicRmwBinOp,
1471         LHS: &'a Value,
1472         RHS: &'a Value,
1473         Order: AtomicOrdering,
1474         SingleThreaded: Bool,
1475     ) -> &'a Value;
1476
1477     pub fn LLVMRustBuildAtomicFence(
1478         B: &Builder<'_>,
1479         Order: AtomicOrdering,
1480         Scope: SynchronizationScope,
1481     );
1482
1483     /// Writes a module to the specified path. Returns 0 on success.
1484     pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1485
1486     /// Creates a pass manager.
1487     pub fn LLVMCreatePassManager() -> &'a mut PassManager<'a>;
1488
1489     /// Creates a function-by-function pass manager
1490     pub fn LLVMCreateFunctionPassManagerForModule(M: &'a Module) -> &'a mut PassManager<'a>;
1491
1492     /// Disposes a pass manager.
1493     pub fn LLVMDisposePassManager(PM: &'a mut PassManager<'a>);
1494
1495     /// Runs a pass manager on a module.
1496     pub fn LLVMRunPassManager(PM: &PassManager<'a>, M: &'a Module) -> Bool;
1497
1498     pub fn LLVMInitializePasses();
1499
1500     pub fn LLVMTimeTraceProfilerInitialize();
1501
1502     pub fn LLVMTimeTraceProfilerFinish(FileName: *const c_char);
1503
1504     pub fn LLVMAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>);
1505
1506     pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1507     pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1508     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool);
1509     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: &PassManagerBuilder, Value: Bool);
1510     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1511         PMB: &PassManagerBuilder,
1512         threshold: c_uint,
1513     );
1514     pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1515         PMB: &PassManagerBuilder,
1516         PM: &PassManager<'_>,
1517     );
1518
1519     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1520         PMB: &PassManagerBuilder,
1521         PM: &PassManager<'_>,
1522     );
1523     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1524         PMB: &PassManagerBuilder,
1525         PM: &PassManager<'_>,
1526         Internalize: Bool,
1527         RunInliner: Bool,
1528     );
1529     pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
1530         PMB: &PassManagerBuilder,
1531         PM: &PassManager<'_>,
1532     );
1533
1534     // Stuff that's in rustllvm/ because it's not upstream yet.
1535
1536     /// Opens an object file.
1537     pub fn LLVMCreateObjectFile(
1538         MemBuf: &'static mut MemoryBuffer,
1539     ) -> Option<&'static mut ObjectFile>;
1540     /// Closes an object file.
1541     pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);
1542
1543     /// Enumerates the sections in an object file.
1544     pub fn LLVMGetSections(ObjFile: &'a ObjectFile) -> &'a mut SectionIterator<'a>;
1545     /// Destroys a section iterator.
1546     pub fn LLVMDisposeSectionIterator(SI: &'a mut SectionIterator<'a>);
1547     /// Returns `true` if the section iterator is at the end of the section
1548     /// list:
1549     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &'a ObjectFile, SI: &SectionIterator<'a>) -> Bool;
1550     /// Moves the section iterator to point to the next section.
1551     pub fn LLVMMoveToNextSection(SI: &SectionIterator<'_>);
1552     /// Returns the current section size.
1553     pub fn LLVMGetSectionSize(SI: &SectionIterator<'_>) -> c_ulonglong;
1554     /// Returns the current section contents as a string buffer.
1555     pub fn LLVMGetSectionContents(SI: &SectionIterator<'_>) -> *const c_char;
1556
1557     /// Reads the given file and returns it as a memory buffer. Use
1558     /// LLVMDisposeMemoryBuffer() to get rid of it.
1559     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1560         Path: *const c_char,
1561     ) -> Option<&'static mut MemoryBuffer>;
1562
1563     pub fn LLVMStartMultithreaded() -> Bool;
1564
1565     /// Returns a string describing the last error caused by an LLVMRust* call.
1566     pub fn LLVMRustGetLastError() -> *const c_char;
1567
1568     /// Print the pass timings since static dtors aren't picking them up.
1569     pub fn LLVMRustPrintPassTimings();
1570
1571     pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1572
1573     pub fn LLVMStructSetBody(
1574         StructTy: &'a Type,
1575         ElementTypes: *const &'a Type,
1576         ElementCount: c_uint,
1577         Packed: Bool,
1578     );
1579
1580     /// Prepares inline assembly.
1581     pub fn LLVMRustInlineAsm(
1582         Ty: &Type,
1583         AsmString: *const c_char,
1584         Constraints: *const c_char,
1585         SideEffects: Bool,
1586         AlignStack: Bool,
1587         Dialect: AsmDialect,
1588     ) -> &Value;
1589     pub fn LLVMRustInlineAsmVerify(Ty: &Type, Constraints: *const c_char) -> bool;
1590
1591     pub fn LLVMRustDebugMetadataVersion() -> u32;
1592     pub fn LLVMRustVersionMajor() -> u32;
1593     pub fn LLVMRustVersionMinor() -> u32;
1594
1595     pub fn LLVMRustAddModuleFlag(M: &Module, name: *const c_char, value: u32);
1596
1597     pub fn LLVMRustMetadataAsValue(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1598
1599     pub fn LLVMRustDIBuilderCreate(M: &'a Module) -> &'a mut DIBuilder<'a>;
1600
1601     pub fn LLVMRustDIBuilderDispose(Builder: &'a mut DIBuilder<'a>);
1602
1603     pub fn LLVMRustDIBuilderFinalize(Builder: &DIBuilder<'_>);
1604
1605     pub fn LLVMRustDIBuilderCreateCompileUnit(
1606         Builder: &DIBuilder<'a>,
1607         Lang: c_uint,
1608         File: &'a DIFile,
1609         Producer: *const c_char,
1610         isOptimized: bool,
1611         Flags: *const c_char,
1612         RuntimeVer: c_uint,
1613         SplitName: *const c_char,
1614         kind: DebugEmissionKind,
1615     ) -> &'a DIDescriptor;
1616
1617     pub fn LLVMRustDIBuilderCreateFile(
1618         Builder: &DIBuilder<'a>,
1619         Filename: *const c_char,
1620         Directory: *const c_char,
1621     ) -> &'a DIFile;
1622
1623     pub fn LLVMRustDIBuilderCreateSubroutineType(
1624         Builder: &DIBuilder<'a>,
1625         File: &'a DIFile,
1626         ParameterTypes: &'a DIArray,
1627     ) -> &'a DICompositeType;
1628
1629     pub fn LLVMRustDIBuilderCreateFunction(
1630         Builder: &DIBuilder<'a>,
1631         Scope: &'a DIDescriptor,
1632         Name: *const c_char,
1633         LinkageName: *const c_char,
1634         File: &'a DIFile,
1635         LineNo: c_uint,
1636         Ty: &'a DIType,
1637         ScopeLine: c_uint,
1638         Flags: DIFlags,
1639         SPFlags: DISPFlags,
1640         Fn: &'a Value,
1641         TParam: &'a DIArray,
1642         Decl: Option<&'a DIDescriptor>,
1643     ) -> &'a DISubprogram;
1644
1645     pub fn LLVMRustDIBuilderCreateBasicType(
1646         Builder: &DIBuilder<'a>,
1647         Name: *const c_char,
1648         SizeInBits: u64,
1649         AlignInBits: u32,
1650         Encoding: c_uint,
1651     ) -> &'a DIBasicType;
1652
1653     pub fn LLVMRustDIBuilderCreatePointerType(
1654         Builder: &DIBuilder<'a>,
1655         PointeeTy: &'a DIType,
1656         SizeInBits: u64,
1657         AlignInBits: u32,
1658         Name: *const c_char,
1659     ) -> &'a DIDerivedType;
1660
1661     pub fn LLVMRustDIBuilderCreateStructType(
1662         Builder: &DIBuilder<'a>,
1663         Scope: Option<&'a DIDescriptor>,
1664         Name: *const c_char,
1665         File: &'a DIFile,
1666         LineNumber: c_uint,
1667         SizeInBits: u64,
1668         AlignInBits: u32,
1669         Flags: DIFlags,
1670         DerivedFrom: Option<&'a DIType>,
1671         Elements: &'a DIArray,
1672         RunTimeLang: c_uint,
1673         VTableHolder: Option<&'a DIType>,
1674         UniqueId: *const c_char,
1675     ) -> &'a DICompositeType;
1676
1677     pub fn LLVMRustDIBuilderCreateMemberType(
1678         Builder: &DIBuilder<'a>,
1679         Scope: &'a DIDescriptor,
1680         Name: *const c_char,
1681         File: &'a DIFile,
1682         LineNo: c_uint,
1683         SizeInBits: u64,
1684         AlignInBits: u32,
1685         OffsetInBits: u64,
1686         Flags: DIFlags,
1687         Ty: &'a DIType,
1688     ) -> &'a DIDerivedType;
1689
1690     pub fn LLVMRustDIBuilderCreateVariantMemberType(
1691         Builder: &DIBuilder<'a>,
1692         Scope: &'a DIScope,
1693         Name: *const c_char,
1694         File: &'a DIFile,
1695         LineNumber: c_uint,
1696         SizeInBits: u64,
1697         AlignInBits: u32,
1698         OffsetInBits: u64,
1699         Discriminant: Option<&'a Value>,
1700         Flags: DIFlags,
1701         Ty: &'a DIType,
1702     ) -> &'a DIType;
1703
1704     pub fn LLVMRustDIBuilderCreateLexicalBlock(
1705         Builder: &DIBuilder<'a>,
1706         Scope: &'a DIScope,
1707         File: &'a DIFile,
1708         Line: c_uint,
1709         Col: c_uint,
1710     ) -> &'a DILexicalBlock;
1711
1712     pub fn LLVMRustDIBuilderCreateLexicalBlockFile(
1713         Builder: &DIBuilder<'a>,
1714         Scope: &'a DIScope,
1715         File: &'a DIFile,
1716     ) -> &'a DILexicalBlock;
1717
1718     pub fn LLVMRustDIBuilderCreateStaticVariable(
1719         Builder: &DIBuilder<'a>,
1720         Context: Option<&'a DIScope>,
1721         Name: *const c_char,
1722         LinkageName: *const c_char,
1723         File: &'a DIFile,
1724         LineNo: c_uint,
1725         Ty: &'a DIType,
1726         isLocalToUnit: bool,
1727         Val: &'a Value,
1728         Decl: Option<&'a DIDescriptor>,
1729         AlignInBits: u32,
1730     ) -> &'a DIGlobalVariableExpression;
1731
1732     pub fn LLVMRustDIBuilderCreateVariable(
1733         Builder: &DIBuilder<'a>,
1734         Tag: c_uint,
1735         Scope: &'a DIDescriptor,
1736         Name: *const c_char,
1737         File: &'a DIFile,
1738         LineNo: c_uint,
1739         Ty: &'a DIType,
1740         AlwaysPreserve: bool,
1741         Flags: DIFlags,
1742         ArgNo: c_uint,
1743         AlignInBits: u32,
1744     ) -> &'a DIVariable;
1745
1746     pub fn LLVMRustDIBuilderCreateArrayType(
1747         Builder: &DIBuilder<'a>,
1748         Size: u64,
1749         AlignInBits: u32,
1750         Ty: &'a DIType,
1751         Subscripts: &'a DIArray,
1752     ) -> &'a DIType;
1753
1754     pub fn LLVMRustDIBuilderGetOrCreateSubrange(
1755         Builder: &DIBuilder<'a>,
1756         Lo: i64,
1757         Count: i64,
1758     ) -> &'a DISubrange;
1759
1760     pub fn LLVMRustDIBuilderGetOrCreateArray(
1761         Builder: &DIBuilder<'a>,
1762         Ptr: *const Option<&'a DIDescriptor>,
1763         Count: c_uint,
1764     ) -> &'a DIArray;
1765
1766     pub fn LLVMRustDIBuilderInsertDeclareAtEnd(
1767         Builder: &DIBuilder<'a>,
1768         Val: &'a Value,
1769         VarInfo: &'a DIVariable,
1770         AddrOps: *const i64,
1771         AddrOpsCount: c_uint,
1772         DL: &'a Value,
1773         InsertAtEnd: &'a BasicBlock,
1774     ) -> &'a Value;
1775
1776     pub fn LLVMRustDIBuilderCreateEnumerator(
1777         Builder: &DIBuilder<'a>,
1778         Name: *const c_char,
1779         Val: u64,
1780     ) -> &'a DIEnumerator;
1781
1782     pub fn LLVMRustDIBuilderCreateEnumerationType(
1783         Builder: &DIBuilder<'a>,
1784         Scope: &'a DIScope,
1785         Name: *const c_char,
1786         File: &'a DIFile,
1787         LineNumber: c_uint,
1788         SizeInBits: u64,
1789         AlignInBits: u32,
1790         Elements: &'a DIArray,
1791         ClassType: &'a DIType,
1792         IsScoped: bool,
1793     ) -> &'a DIType;
1794
1795     pub fn LLVMRustDIBuilderCreateUnionType(
1796         Builder: &DIBuilder<'a>,
1797         Scope: &'a DIScope,
1798         Name: *const c_char,
1799         File: &'a DIFile,
1800         LineNumber: c_uint,
1801         SizeInBits: u64,
1802         AlignInBits: u32,
1803         Flags: DIFlags,
1804         Elements: Option<&'a DIArray>,
1805         RunTimeLang: c_uint,
1806         UniqueId: *const c_char,
1807     ) -> &'a DIType;
1808
1809     pub fn LLVMRustDIBuilderCreateVariantPart(
1810         Builder: &DIBuilder<'a>,
1811         Scope: &'a DIScope,
1812         Name: *const c_char,
1813         File: &'a DIFile,
1814         LineNo: c_uint,
1815         SizeInBits: u64,
1816         AlignInBits: u32,
1817         Flags: DIFlags,
1818         Discriminator: Option<&'a DIDerivedType>,
1819         Elements: &'a DIArray,
1820         UniqueId: *const c_char,
1821     ) -> &'a DIDerivedType;
1822
1823     pub fn LLVMSetUnnamedAddr(GlobalVar: &Value, UnnamedAddr: Bool);
1824
1825     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(
1826         Builder: &DIBuilder<'a>,
1827         Scope: Option<&'a DIScope>,
1828         Name: *const c_char,
1829         Ty: &'a DIType,
1830         File: &'a DIFile,
1831         LineNo: c_uint,
1832         ColumnNo: c_uint,
1833     ) -> &'a DITemplateTypeParameter;
1834
1835     pub fn LLVMRustDIBuilderCreateNameSpace(
1836         Builder: &DIBuilder<'a>,
1837         Scope: Option<&'a DIScope>,
1838         Name: *const c_char,
1839         File: &'a DIFile,
1840         LineNo: c_uint,
1841     ) -> &'a DINameSpace;
1842
1843     pub fn LLVMRustDICompositeTypeReplaceArrays(
1844         Builder: &DIBuilder<'a>,
1845         CompositeType: &'a DIType,
1846         Elements: Option<&'a DIArray>,
1847         Params: Option<&'a DIArray>,
1848     );
1849
1850     pub fn LLVMRustDIBuilderCreateDebugLocation(
1851         Context: &'a Context,
1852         Line: c_uint,
1853         Column: c_uint,
1854         Scope: &'a DIScope,
1855         InlinedAt: Option<&'a Metadata>,
1856     ) -> &'a Value;
1857     pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
1858     pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
1859
1860     #[allow(improper_ctypes)]
1861     pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
1862     #[allow(improper_ctypes)]
1863     pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
1864
1865     pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
1866
1867     pub fn LLVMRustPassKind(Pass: &Pass) -> PassKind;
1868     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
1869     pub fn LLVMRustCreateAddressSanitizerFunctionPass(Recover: bool) -> &'static mut Pass;
1870     pub fn LLVMRustCreateModuleAddressSanitizerPass(Recover: bool) -> &'static mut Pass;
1871     pub fn LLVMRustCreateMemorySanitizerPass(
1872         TrackOrigins: c_int,
1873         Recover: bool,
1874     ) -> &'static mut Pass;
1875     pub fn LLVMRustCreateThreadSanitizerPass() -> &'static mut Pass;
1876     pub fn LLVMRustAddPass(PM: &PassManager<'_>, Pass: &'static mut Pass);
1877     pub fn LLVMRustAddLastExtensionPasses(
1878         PMB: &PassManagerBuilder,
1879         Passes: *const &'static mut Pass,
1880         NumPasses: size_t,
1881     );
1882
1883     pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
1884
1885     pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
1886     pub fn LLVMRustPrintTargetFeatures(T: &TargetMachine);
1887
1888     pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
1889     pub fn LLVMRustCreateTargetMachine(
1890         Triple: *const c_char,
1891         CPU: *const c_char,
1892         Features: *const c_char,
1893         Abi: *const c_char,
1894         Model: CodeModel,
1895         Reloc: RelocMode,
1896         Level: CodeGenOptLevel,
1897         UseSoftFP: bool,
1898         PositionIndependentExecutable: bool,
1899         FunctionSections: bool,
1900         DataSections: bool,
1901         TrapUnreachable: bool,
1902         Singlethread: bool,
1903         AsmComments: bool,
1904         EmitStackSizeSection: bool,
1905         RelaxELFRelocations: bool,
1906     ) -> Option<&'static mut TargetMachine>;
1907     pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
1908     pub fn LLVMRustAddBuilderLibraryInfo(
1909         PMB: &'a PassManagerBuilder,
1910         M: &'a Module,
1911         DisableSimplifyLibCalls: bool,
1912     );
1913     pub fn LLVMRustConfigurePassManagerBuilder(
1914         PMB: &PassManagerBuilder,
1915         OptLevel: CodeGenOptLevel,
1916         MergeFunctions: bool,
1917         SLPVectorize: bool,
1918         LoopVectorize: bool,
1919         PrepareForThinLTO: bool,
1920         PGOGenPath: *const c_char,
1921         PGOUsePath: *const c_char,
1922     );
1923     pub fn LLVMRustAddLibraryInfo(
1924         PM: &PassManager<'a>,
1925         M: &'a Module,
1926         DisableSimplifyLibCalls: bool,
1927     );
1928     pub fn LLVMRustRunFunctionPassManager(PM: &PassManager<'a>, M: &'a Module);
1929     pub fn LLVMRustWriteOutputFile(
1930         T: &'a TargetMachine,
1931         PM: &PassManager<'a>,
1932         M: &'a Module,
1933         Output: *const c_char,
1934         FileType: FileType,
1935     ) -> LLVMRustResult;
1936     pub fn LLVMRustOptimizeWithNewPassManager(
1937         M: &'a Module,
1938         TM: &'a TargetMachine,
1939         OptLevel: PassBuilderOptLevel,
1940         OptStage: OptStage,
1941         NoPrepopulatePasses: bool,
1942         VerifyIR: bool,
1943         UseThinLTOBuffers: bool,
1944         MergeFunctions: bool,
1945         UnrollLoops: bool,
1946         SLPVectorize: bool,
1947         LoopVectorize: bool,
1948         DisableSimplifyLibCalls: bool,
1949         SanitizerOptions: Option<&SanitizerOptions>,
1950         PGOGenPath: *const c_char,
1951         PGOUsePath: *const c_char,
1952         llvm_selfprofiler: *mut c_void,
1953         begin_callback: SelfProfileBeforePassCallback,
1954         end_callback: SelfProfileAfterPassCallback,
1955     );
1956     pub fn LLVMRustPrintModule(
1957         M: &'a Module,
1958         Output: *const c_char,
1959         Demangle: extern "C" fn(*const c_char, size_t, *mut c_char, size_t) -> size_t,
1960     ) -> LLVMRustResult;
1961     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
1962     pub fn LLVMRustPrintPasses();
1963     pub fn LLVMRustGetInstructionCount(M: &Module) -> u32;
1964     pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
1965     pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
1966     pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
1967     pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);
1968
1969     pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
1970     pub fn LLVMRustArchiveIteratorNew(AR: &'a Archive) -> &'a mut ArchiveIterator<'a>;
1971     pub fn LLVMRustArchiveIteratorNext(
1972         AIR: &ArchiveIterator<'a>,
1973     ) -> Option<&'a mut ArchiveChild<'a>>;
1974     pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
1975     pub fn LLVMRustArchiveChildData(ACR: &ArchiveChild<'_>, size: &mut size_t) -> *const c_char;
1976     pub fn LLVMRustArchiveChildFree(ACR: &'a mut ArchiveChild<'a>);
1977     pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
1978     pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
1979
1980     #[allow(improper_ctypes)]
1981     pub fn LLVMRustGetSectionName(
1982         SI: &SectionIterator<'_>,
1983         data: &mut Option<std::ptr::NonNull<c_char>>,
1984     ) -> size_t;
1985
1986     #[allow(improper_ctypes)]
1987     pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
1988
1989     pub fn LLVMContextSetDiagnosticHandler(
1990         C: &Context,
1991         Handler: DiagnosticHandler,
1992         DiagnosticContext: *mut c_void,
1993     );
1994
1995     #[allow(improper_ctypes)]
1996     pub fn LLVMRustUnpackOptimizationDiagnostic(
1997         DI: &'a DiagnosticInfo,
1998         pass_name_out: &RustString,
1999         function_out: &mut Option<&'a Value>,
2000         loc_line_out: &mut c_uint,
2001         loc_column_out: &mut c_uint,
2002         loc_filename_out: &RustString,
2003         message_out: &RustString,
2004     );
2005
2006     pub fn LLVMRustUnpackInlineAsmDiagnostic(
2007         DI: &'a DiagnosticInfo,
2008         cookie_out: &mut c_uint,
2009         message_out: &mut Option<&'a Twine>,
2010         instruction_out: &mut Option<&'a Value>,
2011     );
2012
2013     #[allow(improper_ctypes)]
2014     pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
2015     pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
2016
2017     pub fn LLVMRustSetInlineAsmDiagnosticHandler(
2018         C: &Context,
2019         H: InlineAsmDiagHandler,
2020         CX: *mut c_void,
2021     );
2022
2023     #[allow(improper_ctypes)]
2024     pub fn LLVMRustWriteSMDiagnosticToString(d: &SMDiagnostic, s: &RustString);
2025
2026     pub fn LLVMRustWriteArchive(
2027         Dst: *const c_char,
2028         NumMembers: size_t,
2029         Members: *const &RustArchiveMember<'_>,
2030         WriteSymbtab: bool,
2031         Kind: ArchiveKind,
2032     ) -> LLVMRustResult;
2033     pub fn LLVMRustArchiveMemberNew(
2034         Filename: *const c_char,
2035         Name: *const c_char,
2036         Child: Option<&ArchiveChild<'a>>,
2037     ) -> &'a mut RustArchiveMember<'a>;
2038     pub fn LLVMRustArchiveMemberFree(Member: &'a mut RustArchiveMember<'a>);
2039
2040     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: &'a Module, TM: &'a TargetMachine);
2041
2042     pub fn LLVMRustBuildOperandBundleDef(
2043         Name: *const c_char,
2044         Inputs: *const &'a Value,
2045         NumInputs: c_uint,
2046     ) -> &'a mut OperandBundleDef<'a>;
2047     pub fn LLVMRustFreeOperandBundleDef(Bundle: &'a mut OperandBundleDef<'a>);
2048
2049     pub fn LLVMRustPositionBuilderAtStart(B: &Builder<'a>, BB: &'a BasicBlock);
2050
2051     pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
2052     pub fn LLVMRustUnsetComdat(V: &Value);
2053     pub fn LLVMRustSetModulePICLevel(M: &Module);
2054     pub fn LLVMRustSetModulePIELevel(M: &Module);
2055     pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
2056     pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
2057     pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
2058     pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
2059     pub fn LLVMRustModuleCost(M: &Module) -> u64;
2060
2061     pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
2062     pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
2063     pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
2064     pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2065     pub fn LLVMRustCreateThinLTOData(
2066         Modules: *const ThinLTOModule,
2067         NumModules: c_uint,
2068         PreservedSymbols: *const *const c_char,
2069         PreservedSymbolsLen: c_uint,
2070     ) -> Option<&'static mut ThinLTOData>;
2071     pub fn LLVMRustPrepareThinLTORename(Data: &ThinLTOData, Module: &Module) -> bool;
2072     pub fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool;
2073     pub fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool;
2074     pub fn LLVMRustPrepareThinLTOImport(Data: &ThinLTOData, Module: &Module) -> bool;
2075     pub fn LLVMRustGetThinLTOModuleImports(
2076         Data: *const ThinLTOData,
2077         ModuleNameCallback: ThinLTOModuleNameCallback,
2078         CallbackPayload: *mut c_void,
2079     );
2080     pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
2081     pub fn LLVMRustParseBitcodeForLTO(
2082         Context: &Context,
2083         Data: *const u8,
2084         len: usize,
2085         Identifier: *const c_char,
2086     ) -> Option<&Module>;
2087     pub fn LLVMRustThinLTOGetDICompileUnit(
2088         M: &Module,
2089         CU1: &mut *mut c_void,
2090         CU2: &mut *mut c_void,
2091     );
2092     pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
2093
2094     pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
2095     pub fn LLVMRustLinkerAdd(
2096         linker: &Linker<'_>,
2097         bytecode: *const c_char,
2098         bytecode_len: usize,
2099     ) -> bool;
2100     pub fn LLVMRustLinkerFree(linker: &'a mut Linker<'a>);
2101 }