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