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