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