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