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