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