]> git.lizzy.rs Git - rust.git/blob - src/librustc_llvm/lib.rs
Only retain external static symbols across LTO
[rust.git] / src / librustc_llvm / lib.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 #![allow(non_upper_case_globals)]
12 #![allow(non_camel_case_types)]
13 #![allow(non_snake_case)]
14 #![allow(dead_code)]
15
16 #![crate_name = "rustc_llvm"]
17 #![unstable(feature = "rustc_private", issue = "27812")]
18 #![crate_type = "dylib"]
19 #![crate_type = "rlib"]
20 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
21        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
22        html_root_url = "https://doc.rust-lang.org/nightly/")]
23 #![cfg_attr(not(stage0), deny(warnings))]
24
25 #![feature(associated_consts)]
26 #![feature(box_syntax)]
27 #![feature(libc)]
28 #![feature(link_args)]
29 #![feature(staged_api)]
30 #![feature(linked_from)]
31 #![feature(concat_idents)]
32
33 extern crate libc;
34 #[macro_use] #[no_link] extern crate rustc_bitflags;
35
36 pub use self::OtherAttribute::*;
37 pub use self::SpecialAttribute::*;
38 pub use self::AttributeSet::*;
39 pub use self::IntPredicate::*;
40 pub use self::RealPredicate::*;
41 pub use self::TypeKind::*;
42 pub use self::AtomicBinOp::*;
43 pub use self::AtomicOrdering::*;
44 pub use self::SynchronizationScope::*;
45 pub use self::FileType::*;
46 pub use self::MetadataType::*;
47 pub use self::AsmDialect::*;
48 pub use self::CodeGenOptLevel::*;
49 pub use self::RelocMode::*;
50 pub use self::CodeGenModel::*;
51 pub use self::DiagnosticKind::*;
52 pub use self::CallConv::*;
53 pub use self::Visibility::*;
54 pub use self::DiagnosticSeverity::*;
55 pub use self::Linkage::*;
56 pub use self::DLLStorageClassTypes::*;
57
58 use std::ffi::{CString, CStr};
59 use std::cell::RefCell;
60 use std::slice;
61 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
62 use libc::{c_longlong, c_ulonglong, c_void};
63 use debuginfo::{DIBuilderRef, DIDescriptor,
64                 DIFile, DILexicalBlock, DISubprogram, DIType,
65                 DIBasicType, DIDerivedType, DICompositeType, DIScope,
66                 DIVariable, DIGlobalVariable, DIArray, DISubrange,
67                 DITemplateTypeParameter, DIEnumerator, DINameSpace};
68
69 pub mod archive_ro;
70 pub mod diagnostic;
71
72 pub type Opcode = u32;
73 pub type Bool = c_uint;
74
75 pub const True: Bool = 1 as Bool;
76 pub const False: Bool = 0 as Bool;
77
78 // Consts for the LLVM CallConv type, pre-cast to usize.
79
80 #[derive(Copy, Clone, PartialEq)]
81 pub enum CallConv {
82     CCallConv = 0,
83     FastCallConv = 8,
84     ColdCallConv = 9,
85     X86StdcallCallConv = 64,
86     X86FastcallCallConv = 65,
87     X86_64_Win64 = 79,
88     X86_VectorCall = 80
89 }
90
91 #[derive(Copy, Clone)]
92 pub enum Visibility {
93     LLVMDefaultVisibility = 0,
94     HiddenVisibility = 1,
95     ProtectedVisibility = 2,
96 }
97
98 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
99 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
100 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
101 // they've been removed in upstream LLVM commit r203866.
102 #[derive(Copy, Clone)]
103 pub enum Linkage {
104     ExternalLinkage = 0,
105     AvailableExternallyLinkage = 1,
106     LinkOnceAnyLinkage = 2,
107     LinkOnceODRLinkage = 3,
108     WeakAnyLinkage = 5,
109     WeakODRLinkage = 6,
110     AppendingLinkage = 7,
111     InternalLinkage = 8,
112     PrivateLinkage = 9,
113     ExternalWeakLinkage = 12,
114     CommonLinkage = 14,
115 }
116
117 #[repr(C)]
118 #[derive(Copy, Clone, Debug)]
119 pub enum DiagnosticSeverity {
120     Error,
121     Warning,
122     Remark,
123     Note,
124 }
125
126
127 #[repr(C)]
128 #[derive(Copy, Clone)]
129 pub enum DLLStorageClassTypes {
130     DefaultStorageClass = 0,
131     DLLImportStorageClass = 1,
132     DLLExportStorageClass = 2,
133 }
134
135 bitflags! {
136     flags Attribute : u64 {
137         const ZExt            = 1 << 0,
138         const SExt            = 1 << 1,
139         const NoReturn        = 1 << 2,
140         const InReg           = 1 << 3,
141         const StructRet       = 1 << 4,
142         const NoUnwind        = 1 << 5,
143         const NoAlias         = 1 << 6,
144         const ByVal           = 1 << 7,
145         const Nest            = 1 << 8,
146         const ReadNone        = 1 << 9,
147         const ReadOnly        = 1 << 10,
148         const NoInline        = 1 << 11,
149         const AlwaysInline    = 1 << 12,
150         const OptimizeForSize = 1 << 13,
151         const StackProtect    = 1 << 14,
152         const StackProtectReq = 1 << 15,
153         const Alignment       = 1 << 16,
154         const NoCapture       = 1 << 21,
155         const NoRedZone       = 1 << 22,
156         const NoImplicitFloat = 1 << 23,
157         const Naked           = 1 << 24,
158         const InlineHint      = 1 << 25,
159         const Stack           = 7 << 26,
160         const ReturnsTwice    = 1 << 29,
161         const UWTable         = 1 << 30,
162         const NonLazyBind     = 1 << 31,
163         const OptimizeNone    = 1 << 42,
164     }
165 }
166
167
168 #[repr(u64)]
169 #[derive(Copy, Clone)]
170 pub enum OtherAttribute {
171     // The following are not really exposed in
172     // the LLVM C api so instead to add these
173     // we call a wrapper function in RustWrapper
174     // that uses the C++ api.
175     SanitizeAddressAttribute = 1 << 32,
176     MinSizeAttribute = 1 << 33,
177     NoDuplicateAttribute = 1 << 34,
178     StackProtectStrongAttribute = 1 << 35,
179     SanitizeThreadAttribute = 1 << 36,
180     SanitizeMemoryAttribute = 1 << 37,
181     NoBuiltinAttribute = 1 << 38,
182     ReturnedAttribute = 1 << 39,
183     ColdAttribute = 1 << 40,
184     BuiltinAttribute = 1 << 41,
185     OptimizeNoneAttribute = 1 << 42,
186     InAllocaAttribute = 1 << 43,
187     NonNullAttribute = 1 << 44,
188 }
189
190 #[derive(Copy, Clone)]
191 pub enum SpecialAttribute {
192     DereferenceableAttribute(u64)
193 }
194
195 #[repr(C)]
196 #[derive(Copy, Clone)]
197 pub enum AttributeSet {
198     ReturnIndex = 0,
199     FunctionIndex = !0
200 }
201
202 pub trait AttrHelper {
203     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
204     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
205 }
206
207 impl AttrHelper for Attribute {
208     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
209         unsafe {
210             LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
211         }
212     }
213
214     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
215         unsafe {
216             LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
217         }
218     }
219 }
220
221 impl AttrHelper for OtherAttribute {
222     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
223         unsafe {
224             LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
225         }
226     }
227
228     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
229         unsafe {
230             LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
231         }
232     }
233 }
234
235 impl AttrHelper for SpecialAttribute {
236     fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
237         match *self {
238             DereferenceableAttribute(bytes) => unsafe {
239                 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
240             }
241         }
242     }
243
244     fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
245         match *self {
246             DereferenceableAttribute(bytes) => unsafe {
247                 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
248             }
249         }
250     }
251 }
252
253 pub struct AttrBuilder {
254     attrs: Vec<(usize, Box<AttrHelper+'static>)>
255 }
256
257 impl AttrBuilder {
258     pub fn new() -> AttrBuilder {
259         AttrBuilder {
260             attrs: Vec::new()
261         }
262     }
263
264     pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: usize, a: T) -> &'a mut AttrBuilder {
265         self.attrs.push((idx, box a as Box<AttrHelper+'static>));
266         self
267     }
268
269     pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
270         self.attrs.push((ReturnIndex as usize, box a as Box<AttrHelper+'static>));
271         self
272     }
273
274     pub fn apply_llfn(&self, llfn: ValueRef) {
275         for &(idx, ref attr) in &self.attrs {
276             attr.apply_llfn(idx as c_uint, llfn);
277         }
278     }
279
280     pub fn apply_callsite(&self, callsite: ValueRef) {
281         for &(idx, ref attr) in &self.attrs {
282             attr.apply_callsite(idx as c_uint, callsite);
283         }
284     }
285 }
286
287 // enum for the LLVM IntPredicate type
288 #[derive(Copy, Clone)]
289 pub enum IntPredicate {
290     IntEQ = 32,
291     IntNE = 33,
292     IntUGT = 34,
293     IntUGE = 35,
294     IntULT = 36,
295     IntULE = 37,
296     IntSGT = 38,
297     IntSGE = 39,
298     IntSLT = 40,
299     IntSLE = 41,
300 }
301
302 // enum for the LLVM RealPredicate type
303 #[derive(Copy, Clone)]
304 pub enum RealPredicate {
305     RealPredicateFalse = 0,
306     RealOEQ = 1,
307     RealOGT = 2,
308     RealOGE = 3,
309     RealOLT = 4,
310     RealOLE = 5,
311     RealONE = 6,
312     RealORD = 7,
313     RealUNO = 8,
314     RealUEQ = 9,
315     RealUGT = 10,
316     RealUGE = 11,
317     RealULT = 12,
318     RealULE = 13,
319     RealUNE = 14,
320     RealPredicateTrue = 15,
321 }
322
323 // The LLVM TypeKind type - must stay in sync with the def of
324 // LLVMTypeKind in llvm/include/llvm-c/Core.h
325 #[derive(Copy, Clone, PartialEq, Debug)]
326 #[repr(C)]
327 pub enum TypeKind {
328     Void      = 0,
329     Half      = 1,
330     Float     = 2,
331     Double    = 3,
332     X86_FP80  = 4,
333     FP128     = 5,
334     PPC_FP128 = 6,
335     Label     = 7,
336     Integer   = 8,
337     Function  = 9,
338     Struct    = 10,
339     Array     = 11,
340     Pointer   = 12,
341     Vector    = 13,
342     Metadata  = 14,
343     X86_MMX   = 15,
344 }
345
346 #[repr(C)]
347 #[derive(Copy, Clone)]
348 pub enum AtomicBinOp {
349     AtomicXchg = 0,
350     AtomicAdd  = 1,
351     AtomicSub  = 2,
352     AtomicAnd  = 3,
353     AtomicNand = 4,
354     AtomicOr   = 5,
355     AtomicXor  = 6,
356     AtomicMax  = 7,
357     AtomicMin  = 8,
358     AtomicUMax = 9,
359     AtomicUMin = 10,
360 }
361
362 #[repr(C)]
363 #[derive(Copy, Clone)]
364 pub enum AtomicOrdering {
365     NotAtomic = 0,
366     Unordered = 1,
367     Monotonic = 2,
368     // Consume = 3,  // Not specified yet.
369     Acquire = 4,
370     Release = 5,
371     AcquireRelease = 6,
372     SequentiallyConsistent = 7
373 }
374
375 #[repr(C)]
376 #[derive(Copy, Clone)]
377 pub enum SynchronizationScope {
378     SingleThread = 0,
379     CrossThread = 1
380 }
381
382 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
383 #[repr(C)]
384 #[derive(Copy, Clone)]
385 pub enum FileType {
386     AssemblyFileType = 0,
387     ObjectFileType = 1
388 }
389
390 #[derive(Copy, Clone)]
391 pub enum MetadataType {
392     MD_dbg = 0,
393     MD_tbaa = 1,
394     MD_prof = 2,
395     MD_fpmath = 3,
396     MD_range = 4,
397     MD_tbaa_struct = 5,
398     MD_invariant_load = 6,
399     MD_alias_scope = 7,
400     MD_noalias = 8,
401     MD_nontemporal = 9,
402     MD_mem_parallel_loop_access = 10,
403     MD_nonnull = 11,
404 }
405
406 // Inline Asm Dialect
407 #[derive(Copy, Clone)]
408 pub enum AsmDialect {
409     AD_ATT   = 0,
410     AD_Intel = 1
411 }
412
413 #[derive(Copy, Clone, PartialEq)]
414 #[repr(C)]
415 pub enum CodeGenOptLevel {
416     CodeGenLevelNone = 0,
417     CodeGenLevelLess = 1,
418     CodeGenLevelDefault = 2,
419     CodeGenLevelAggressive = 3,
420 }
421
422 #[derive(Copy, Clone, PartialEq)]
423 #[repr(C)]
424 pub enum RelocMode {
425     RelocDefault = 0,
426     RelocStatic = 1,
427     RelocPIC = 2,
428     RelocDynamicNoPic = 3,
429 }
430
431 #[repr(C)]
432 #[derive(Copy, Clone)]
433 pub enum CodeGenModel {
434     CodeModelDefault = 0,
435     CodeModelJITDefault = 1,
436     CodeModelSmall = 2,
437     CodeModelKernel = 3,
438     CodeModelMedium = 4,
439     CodeModelLarge = 5,
440 }
441
442 #[repr(C)]
443 #[derive(Copy, Clone)]
444 pub enum DiagnosticKind {
445     DK_InlineAsm = 0,
446     DK_StackSize,
447     DK_DebugMetadataVersion,
448     DK_SampleProfile,
449     DK_OptimizationRemark,
450     DK_OptimizationRemarkMissed,
451     DK_OptimizationRemarkAnalysis,
452     DK_OptimizationFailure,
453 }
454
455 #[repr(C)]
456 #[derive(Copy, Clone)]
457 pub enum ArchiveKind {
458     K_GNU,
459     K_MIPS64,
460     K_BSD,
461     K_COFF,
462 }
463
464 /// Represents the different LLVM passes Rust supports
465 #[derive(Copy, Clone, PartialEq, Debug)]
466 #[repr(C)]
467 pub enum SupportedPassKind {
468     Function,
469     Module,
470     Unsupported,
471 }
472
473 // Opaque pointer types
474 #[allow(missing_copy_implementations)]
475 pub enum Module_opaque {}
476 pub type ModuleRef = *mut Module_opaque;
477 #[allow(missing_copy_implementations)]
478 pub enum Context_opaque {}
479 pub type ContextRef = *mut Context_opaque;
480 #[allow(missing_copy_implementations)]
481 pub enum Type_opaque {}
482 pub type TypeRef = *mut Type_opaque;
483 #[allow(missing_copy_implementations)]
484 pub enum Value_opaque {}
485 pub type ValueRef = *mut Value_opaque;
486 #[allow(missing_copy_implementations)]
487 pub enum Metadata_opaque {}
488 pub type MetadataRef = *mut Metadata_opaque;
489 #[allow(missing_copy_implementations)]
490 pub enum BasicBlock_opaque {}
491 pub type BasicBlockRef = *mut BasicBlock_opaque;
492 #[allow(missing_copy_implementations)]
493 pub enum Builder_opaque {}
494 pub type BuilderRef = *mut Builder_opaque;
495 #[allow(missing_copy_implementations)]
496 pub enum ExecutionEngine_opaque {}
497 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
498 #[allow(missing_copy_implementations)]
499 pub enum MemoryBuffer_opaque {}
500 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
501 #[allow(missing_copy_implementations)]
502 pub enum PassManager_opaque {}
503 pub type PassManagerRef = *mut PassManager_opaque;
504 #[allow(missing_copy_implementations)]
505 pub enum PassManagerBuilder_opaque {}
506 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
507 #[allow(missing_copy_implementations)]
508 pub enum Use_opaque {}
509 pub type UseRef = *mut Use_opaque;
510 #[allow(missing_copy_implementations)]
511 pub enum TargetData_opaque {}
512 pub type TargetDataRef = *mut TargetData_opaque;
513 #[allow(missing_copy_implementations)]
514 pub enum ObjectFile_opaque {}
515 pub type ObjectFileRef = *mut ObjectFile_opaque;
516 #[allow(missing_copy_implementations)]
517 pub enum SectionIterator_opaque {}
518 pub type SectionIteratorRef = *mut SectionIterator_opaque;
519 #[allow(missing_copy_implementations)]
520 pub enum Pass_opaque {}
521 pub type PassRef = *mut Pass_opaque;
522 #[allow(missing_copy_implementations)]
523 pub enum TargetMachine_opaque {}
524 pub type TargetMachineRef = *mut TargetMachine_opaque;
525 pub enum Archive_opaque {}
526 pub type ArchiveRef = *mut Archive_opaque;
527 pub enum ArchiveIterator_opaque {}
528 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
529 pub enum ArchiveChild_opaque {}
530 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
531 #[allow(missing_copy_implementations)]
532 pub enum Twine_opaque {}
533 pub type TwineRef = *mut Twine_opaque;
534 #[allow(missing_copy_implementations)]
535 pub enum DiagnosticInfo_opaque {}
536 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
537 #[allow(missing_copy_implementations)]
538 pub enum DebugLoc_opaque {}
539 pub type DebugLocRef = *mut DebugLoc_opaque;
540 #[allow(missing_copy_implementations)]
541 pub enum SMDiagnostic_opaque {}
542 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
543 #[allow(missing_copy_implementations)]
544 pub enum RustArchiveMember_opaque {}
545 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
546 #[allow(missing_copy_implementations)]
547 pub enum OperandBundleDef_opaque {}
548 pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
549
550 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
551 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
552
553 pub mod debuginfo {
554     pub use self::DIDescriptorFlags::*;
555     use super::{MetadataRef};
556
557     #[allow(missing_copy_implementations)]
558     pub enum DIBuilder_opaque {}
559     pub type DIBuilderRef = *mut DIBuilder_opaque;
560
561     pub type DIDescriptor = MetadataRef;
562     pub type DIScope = DIDescriptor;
563     pub type DILocation = DIDescriptor;
564     pub type DIFile = DIScope;
565     pub type DILexicalBlock = DIScope;
566     pub type DISubprogram = DIScope;
567     pub type DINameSpace = DIScope;
568     pub type DIType = DIDescriptor;
569     pub type DIBasicType = DIType;
570     pub type DIDerivedType = DIType;
571     pub type DICompositeType = DIDerivedType;
572     pub type DIVariable = DIDescriptor;
573     pub type DIGlobalVariable = DIDescriptor;
574     pub type DIArray = DIDescriptor;
575     pub type DISubrange = DIDescriptor;
576     pub type DIEnumerator = DIDescriptor;
577     pub type DITemplateTypeParameter = DIDescriptor;
578
579     #[derive(Copy, Clone)]
580     pub enum DIDescriptorFlags {
581       FlagPrivate            = 1 << 0,
582       FlagProtected          = 1 << 1,
583       FlagFwdDecl            = 1 << 2,
584       FlagAppleBlock         = 1 << 3,
585       FlagBlockByrefStruct   = 1 << 4,
586       FlagVirtual            = 1 << 5,
587       FlagArtificial         = 1 << 6,
588       FlagExplicit           = 1 << 7,
589       FlagPrototyped         = 1 << 8,
590       FlagObjcClassComplete  = 1 << 9,
591       FlagObjectPointer      = 1 << 10,
592       FlagVector             = 1 << 11,
593       FlagStaticMember       = 1 << 12,
594       FlagIndirectVariable   = 1 << 13,
595       FlagLValueReference    = 1 << 14,
596       FlagRValueReference    = 1 << 15
597     }
598 }
599
600
601 // Link to our native llvm bindings (things that we need to use the C++ api
602 // for) and because llvm is written in C++ we need to link against libstdc++
603 //
604 // You'll probably notice that there is an omission of all LLVM libraries
605 // from this location. This is because the set of LLVM libraries that we
606 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
607 // figure out the exact set of libraries. To do this, the build system
608 // generates an llvmdeps.rs file next to this one which will be
609 // automatically updated whenever LLVM is updated to include an up-to-date
610 // set of the libraries we need to link to LLVM for.
611 #[link(name = "rustllvm", kind = "static")]
612 #[linked_from = "rustllvm"] // not quite true but good enough
613 extern {
614     /* Create and destroy contexts. */
615     pub fn LLVMContextCreate() -> ContextRef;
616     pub fn LLVMContextDispose(C: ContextRef);
617     pub fn LLVMGetMDKindIDInContext(C: ContextRef,
618                                     Name: *const c_char,
619                                     SLen: c_uint)
620                                     -> c_uint;
621
622     /* Create and destroy modules. */
623     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
624                                              C: ContextRef)
625                                              -> ModuleRef;
626     pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
627     pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
628     pub fn LLVMDisposeModule(M: ModuleRef);
629
630     /// Data layout. See Module::getDataLayout.
631     pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
632     pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
633
634     /// Target triple. See Module::getTargetTriple.
635     pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
636     pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
637
638     /// See Module::dump.
639     pub fn LLVMDumpModule(M: ModuleRef);
640
641     /// See Module::setModuleInlineAsm.
642     pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
643
644     /// See llvm::LLVMTypeKind::getTypeID.
645     pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
646
647     /// See llvm::LLVMType::getContext.
648     pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
649
650     /* Operations on integer types */
651     pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
652     pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
653     pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
654     pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
655     pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
656     pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
657                                 -> TypeRef;
658
659     pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
660
661     /* Operations on real types */
662     pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
663     pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
664     pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
665     pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
666     pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
667
668     /* Operations on function types */
669     pub fn LLVMFunctionType(ReturnType: TypeRef,
670                             ParamTypes: *const TypeRef,
671                             ParamCount: c_uint,
672                             IsVarArg: Bool)
673                             -> TypeRef;
674     pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
675     pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
676     pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
677     pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
678
679     /* Operations on struct types */
680     pub fn LLVMStructTypeInContext(C: ContextRef,
681                                    ElementTypes: *const TypeRef,
682                                    ElementCount: c_uint,
683                                    Packed: Bool)
684                                    -> TypeRef;
685     pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
686     pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
687                                      Dest: *mut TypeRef);
688     pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
689
690     /* Operations on array, pointer, and vector types (sequence types) */
691     pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
692     pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
693                            -> TypeRef;
694     pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
695                           -> TypeRef;
696
697     pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
698     pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
699     pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
700     pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
701                                   -> *const c_void;
702     pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
703
704     /* Operations on other types */
705     pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
706     pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
707     pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
708
709     /* Operations on all values */
710     pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
711     pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
712     pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
713     pub fn LLVMDumpValue(Val: ValueRef);
714     pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
715     pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
716     pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
717     pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
718
719     /* Operations on Uses */
720     pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
721     pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
722     pub fn LLVMGetUser(U: UseRef) -> ValueRef;
723     pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
724
725     /* Operations on Users */
726     pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
727     pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
728     pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
729
730     /* Operations on constants of any type */
731     pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
732     /* all zeroes */
733     pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
734     pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
735                          -> ValueRef;
736     pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
737                          -> ValueRef;
738     /* only for isize/vector */
739     pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
740     pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
741     pub fn LLVMIsNull(Val: ValueRef) -> Bool;
742     pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
743     pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
744
745     /* Operations on metadata */
746     pub fn LLVMMDStringInContext(C: ContextRef,
747                                  Str: *const c_char,
748                                  SLen: c_uint)
749                                  -> ValueRef;
750     pub fn LLVMMDNodeInContext(C: ContextRef,
751                                Vals: *const ValueRef,
752                                Count: c_uint)
753                                -> ValueRef;
754     pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
755                                        Str: *const c_char,
756                                        Val: ValueRef);
757
758     /* Operations on scalar constants */
759     pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
760                         -> ValueRef;
761     pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
762                                 -> ValueRef;
763     pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
764                                        Text: *const c_char,
765                                        SLen: c_uint,
766                                        Radix: u8)
767                                        -> ValueRef;
768     pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
769     pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
770                                  -> ValueRef;
771     pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
772                                         Text: *const c_char,
773                                         SLen: c_uint)
774                                         -> ValueRef;
775     pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
776     pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
777
778
779     /* Operations on composite constants */
780     pub fn LLVMConstStringInContext(C: ContextRef,
781                                     Str: *const c_char,
782                                     Length: c_uint,
783                                     DontNullTerminate: Bool)
784                                     -> ValueRef;
785     pub fn LLVMConstStructInContext(C: ContextRef,
786                                     ConstantVals: *const ValueRef,
787                                     Count: c_uint,
788                                     Packed: Bool)
789                                     -> ValueRef;
790
791     pub fn LLVMConstArray(ElementTy: TypeRef,
792                           ConstantVals: *const ValueRef,
793                           Length: c_uint)
794                           -> ValueRef;
795     pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
796                            -> ValueRef;
797
798     /* Constant expressions */
799     pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
800     pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
801     pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
802     pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
803     pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
804     pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
805     pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
806     pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
807                         -> ValueRef;
808     pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
809                            -> ValueRef;
810     pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
811                            -> ValueRef;
812     pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
813                          -> ValueRef;
814     pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
815                         -> ValueRef;
816     pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
817                            -> ValueRef;
818     pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
819                            -> ValueRef;
820     pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
821                          -> ValueRef;
822     pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
823                         -> ValueRef;
824     pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
825                            -> ValueRef;
826     pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
827                            -> ValueRef;
828     pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
829                          -> ValueRef;
830     pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
831                          -> ValueRef;
832     pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
833                          -> ValueRef;
834     pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
835                               RHSConstant: ValueRef)
836                               -> ValueRef;
837     pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
838                          -> ValueRef;
839     pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
840                          -> ValueRef;
841     pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
842                          -> ValueRef;
843     pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
844                          -> ValueRef;
845     pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
846                         -> ValueRef;
847     pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
848                        -> ValueRef;
849     pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
850                         -> ValueRef;
851     pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
852                         -> ValueRef;
853     pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
854                          -> ValueRef;
855     pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
856                          -> ValueRef;
857     pub fn LLVMConstGEP(ConstantVal: ValueRef,
858                         ConstantIndices: *const ValueRef,
859                         NumIndices: c_uint)
860                         -> ValueRef;
861     pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
862                                 ConstantIndices: *const ValueRef,
863                                 NumIndices: c_uint)
864                                 -> ValueRef;
865     pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
866                           -> ValueRef;
867     pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
868                          -> ValueRef;
869     pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
870                          -> ValueRef;
871     pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
872                             -> ValueRef;
873     pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
874                           -> ValueRef;
875     pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
876                            -> ValueRef;
877     pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
878                            -> ValueRef;
879     pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
880                            -> ValueRef;
881     pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
882                            -> ValueRef;
883     pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
884                              -> ValueRef;
885     pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
886                              -> ValueRef;
887     pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
888                             -> ValueRef;
889     pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
890                                   -> ValueRef;
891     pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
892                                   -> ValueRef;
893     pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
894                                    -> ValueRef;
895     pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
896                                 -> ValueRef;
897     pub fn LLVMConstIntCast(ConstantVal: ValueRef,
898                             ToType: TypeRef,
899                             isSigned: Bool)
900                             -> ValueRef;
901     pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
902                            -> ValueRef;
903     pub fn LLVMConstSelect(ConstantCondition: ValueRef,
904                            ConstantIfTrue: ValueRef,
905                            ConstantIfFalse: ValueRef)
906                            -> ValueRef;
907     pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
908                                    IndexConstant: ValueRef)
909                                    -> ValueRef;
910     pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
911                                   ElementValueConstant: ValueRef,
912                                   IndexConstant: ValueRef)
913                                   -> ValueRef;
914     pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
915                                   VectorBConstant: ValueRef,
916                                   MaskConstant: ValueRef)
917                                   -> ValueRef;
918     pub fn LLVMConstExtractValue(AggConstant: ValueRef,
919                                  IdxList: *const c_uint,
920                                  NumIdx: c_uint)
921                                  -> ValueRef;
922     pub fn LLVMConstInsertValue(AggConstant: ValueRef,
923                                 ElementValueConstant: ValueRef,
924                                 IdxList: *const c_uint,
925                                 NumIdx: c_uint)
926                                 -> ValueRef;
927     pub fn LLVMConstInlineAsm(Ty: TypeRef,
928                               AsmString: *const c_char,
929                               Constraints: *const c_char,
930                               HasSideEffects: Bool,
931                               IsAlignStack: Bool)
932                               -> ValueRef;
933     pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
934
935
936
937     /* Operations on global variables, functions, and aliases (globals) */
938     pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
939     pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
940     pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
941     pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
942     pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
943     pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
944     pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
945     pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
946     pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
947     pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
948
949
950     /* Operations on global variables */
951     pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
952     pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
953                          -> ValueRef;
954     pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
955                                        Ty: TypeRef,
956                                        Name: *const c_char,
957                                        AddressSpace: c_uint)
958                                        -> ValueRef;
959     pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
960     pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
961     pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
962     pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
963     pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
964     pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
965     pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
966     pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
967     pub fn LLVMSetInitializer(GlobalVar: ValueRef,
968                               ConstantVal: ValueRef);
969     pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
970     pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
971     pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
972     pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
973     pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
974
975     /* Operations on aliases */
976     pub fn LLVMAddAlias(M: ModuleRef,
977                         Ty: TypeRef,
978                         Aliasee: ValueRef,
979                         Name: *const c_char)
980                         -> ValueRef;
981
982     /* Operations on functions */
983     pub fn LLVMAddFunction(M: ModuleRef,
984                            Name: *const c_char,
985                            FunctionTy: TypeRef)
986                            -> ValueRef;
987     pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
988     pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
989     pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
990     pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
991     pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
992     pub fn LLVMDeleteFunction(Fn: ValueRef);
993     pub fn LLVMGetOrInsertFunction(M: ModuleRef,
994                                    Name: *const c_char,
995                                    FunctionTy: TypeRef)
996                                    -> ValueRef;
997     pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
998     pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
999     pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
1000     pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
1001     pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
1002     pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
1003     pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
1004     pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1005     pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
1006                                           Name: *const c_char,
1007                                           Value: *const c_char);
1008     pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1009     pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
1010     pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
1011
1012     /* Operations on parameters */
1013     pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1014     pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1015     pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1016     pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1017     pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1018     pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1019     pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1020     pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1021     pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1022     pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1023     pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1024     pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1025
1026     /* Operations on basic blocks */
1027     pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1028     pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1029     pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1030     pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1031     pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1032     pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1033     pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1034     pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1035     pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1036     pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1037     pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1038
1039     pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1040                                          Fn: ValueRef,
1041                                          Name: *const c_char)
1042                                          -> BasicBlockRef;
1043     pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1044                                          BB: BasicBlockRef,
1045                                          Name: *const c_char)
1046                                          -> BasicBlockRef;
1047     pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1048
1049     pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1050                                    MoveAfter: BasicBlockRef);
1051
1052     pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1053                                     MoveBefore: BasicBlockRef);
1054
1055     /* Operations on instructions */
1056     pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1057     pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1058     pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1059     pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1060     pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1061     pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1062
1063     /* Operations on call sites */
1064     pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1065     pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1066     pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1067                                  index: c_uint,
1068                                  IA: c_uint);
1069     pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1070                                     index: c_uint,
1071                                     IA: c_uint);
1072     pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1073                                       index: c_uint,
1074                                       align: c_uint);
1075     pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1076                                     index: c_uint,
1077                                     Val: uint64_t);
1078     pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1079                                               index: c_uint,
1080                                               bytes: uint64_t);
1081
1082     /* Operations on call instructions (only) */
1083     pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1084     pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1085
1086     /* Operations on load/store instructions (only) */
1087     pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1088     pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1089
1090     /* Operations on phi nodes */
1091     pub fn LLVMAddIncoming(PhiNode: ValueRef,
1092                            IncomingValues: *const ValueRef,
1093                            IncomingBlocks: *const BasicBlockRef,
1094                            Count: c_uint);
1095     pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1096     pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1097                                 -> ValueRef;
1098     pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1099                                 -> BasicBlockRef;
1100
1101     /* Instruction builders */
1102     pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1103     pub fn LLVMPositionBuilder(Builder: BuilderRef,
1104                                Block: BasicBlockRef,
1105                                Instr: ValueRef);
1106     pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1107                                      Instr: ValueRef);
1108     pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1109                                     Block: BasicBlockRef);
1110     pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1111     pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1112     pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1113     pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1114                                          Instr: ValueRef,
1115                                          Name: *const c_char);
1116     pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1117
1118     /* Execution engine */
1119     pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1120     pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1121     pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1122     pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1123     pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1124     pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1125                                            -> Bool;
1126
1127     /* Metadata */
1128     pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1129     pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1130     pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1131
1132     /* Terminators */
1133     pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1134     pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1135     pub fn LLVMBuildAggregateRet(B: BuilderRef,
1136                                  RetVals: *const ValueRef,
1137                                  N: c_uint)
1138                                  -> ValueRef;
1139     pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1140     pub fn LLVMBuildCondBr(B: BuilderRef,
1141                            If: ValueRef,
1142                            Then: BasicBlockRef,
1143                            Else: BasicBlockRef)
1144                            -> ValueRef;
1145     pub fn LLVMBuildSwitch(B: BuilderRef,
1146                            V: ValueRef,
1147                            Else: BasicBlockRef,
1148                            NumCases: c_uint)
1149                            -> ValueRef;
1150     pub fn LLVMBuildIndirectBr(B: BuilderRef,
1151                                Addr: ValueRef,
1152                                NumDests: c_uint)
1153                                -> ValueRef;
1154     pub fn LLVMRustBuildInvoke(B: BuilderRef,
1155                                Fn: ValueRef,
1156                                Args: *const ValueRef,
1157                                NumArgs: c_uint,
1158                                Then: BasicBlockRef,
1159                                Catch: BasicBlockRef,
1160                                Bundle: OperandBundleDefRef,
1161                                Name: *const c_char)
1162                                -> ValueRef;
1163     pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1164                                    Ty: TypeRef,
1165                                    PersFn: ValueRef,
1166                                    NumClauses: c_uint,
1167                                    Name: *const c_char,
1168                                    F: ValueRef)
1169                                    -> ValueRef;
1170     pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1171     pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1172
1173     pub fn LLVMRustBuildCleanupPad(B: BuilderRef,
1174                                    ParentPad: ValueRef,
1175                                    ArgCnt: c_uint,
1176                                    Args: *const ValueRef,
1177                                    Name: *const c_char) -> ValueRef;
1178     pub fn LLVMRustBuildCleanupRet(B: BuilderRef,
1179                                    CleanupPad: ValueRef,
1180                                    UnwindBB: BasicBlockRef) -> ValueRef;
1181     pub fn LLVMRustBuildCatchPad(B: BuilderRef,
1182                                  ParentPad: ValueRef,
1183                                  ArgCnt: c_uint,
1184                                  Args: *const ValueRef,
1185                                  Name: *const c_char) -> ValueRef;
1186     pub fn LLVMRustBuildCatchRet(B: BuilderRef,
1187                                  Pad: ValueRef,
1188                                  BB: BasicBlockRef) -> ValueRef;
1189     pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef,
1190                                     ParentPad: ValueRef,
1191                                     BB: BasicBlockRef,
1192                                     NumHandlers: c_uint,
1193                                     Name: *const c_char) -> ValueRef;
1194     pub fn LLVMRustAddHandler(CatchSwitch: ValueRef,
1195                               Handler: BasicBlockRef);
1196     pub fn LLVMRustSetPersonalityFn(B: BuilderRef, Pers: ValueRef);
1197
1198     /* Add a case to the switch instruction */
1199     pub fn LLVMAddCase(Switch: ValueRef,
1200                        OnVal: ValueRef,
1201                        Dest: BasicBlockRef);
1202
1203     /* Add a destination to the indirectbr instruction */
1204     pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1205
1206     /* Add a clause to the landing pad instruction */
1207     pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1208
1209     /* Set the cleanup on a landing pad instruction */
1210     pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1211
1212     /* Arithmetic */
1213     pub fn LLVMBuildAdd(B: BuilderRef,
1214                         LHS: ValueRef,
1215                         RHS: ValueRef,
1216                         Name: *const c_char)
1217                         -> ValueRef;
1218     pub fn LLVMBuildNSWAdd(B: BuilderRef,
1219                            LHS: ValueRef,
1220                            RHS: ValueRef,
1221                            Name: *const c_char)
1222                            -> ValueRef;
1223     pub fn LLVMBuildNUWAdd(B: BuilderRef,
1224                            LHS: ValueRef,
1225                            RHS: ValueRef,
1226                            Name: *const c_char)
1227                            -> ValueRef;
1228     pub fn LLVMBuildFAdd(B: BuilderRef,
1229                          LHS: ValueRef,
1230                          RHS: ValueRef,
1231                          Name: *const c_char)
1232                          -> ValueRef;
1233     pub fn LLVMBuildSub(B: BuilderRef,
1234                         LHS: ValueRef,
1235                         RHS: ValueRef,
1236                         Name: *const c_char)
1237                         -> ValueRef;
1238     pub fn LLVMBuildNSWSub(B: BuilderRef,
1239                            LHS: ValueRef,
1240                            RHS: ValueRef,
1241                            Name: *const c_char)
1242                            -> ValueRef;
1243     pub fn LLVMBuildNUWSub(B: BuilderRef,
1244                            LHS: ValueRef,
1245                            RHS: ValueRef,
1246                            Name: *const c_char)
1247                            -> ValueRef;
1248     pub fn LLVMBuildFSub(B: BuilderRef,
1249                          LHS: ValueRef,
1250                          RHS: ValueRef,
1251                          Name: *const c_char)
1252                          -> ValueRef;
1253     pub fn LLVMBuildMul(B: BuilderRef,
1254                         LHS: ValueRef,
1255                         RHS: ValueRef,
1256                         Name: *const c_char)
1257                         -> ValueRef;
1258     pub fn LLVMBuildNSWMul(B: BuilderRef,
1259                            LHS: ValueRef,
1260                            RHS: ValueRef,
1261                            Name: *const c_char)
1262                            -> ValueRef;
1263     pub fn LLVMBuildNUWMul(B: BuilderRef,
1264                            LHS: ValueRef,
1265                            RHS: ValueRef,
1266                            Name: *const c_char)
1267                            -> ValueRef;
1268     pub fn LLVMBuildFMul(B: BuilderRef,
1269                          LHS: ValueRef,
1270                          RHS: ValueRef,
1271                          Name: *const c_char)
1272                          -> ValueRef;
1273     pub fn LLVMBuildUDiv(B: BuilderRef,
1274                          LHS: ValueRef,
1275                          RHS: ValueRef,
1276                          Name: *const c_char)
1277                          -> ValueRef;
1278     pub fn LLVMBuildSDiv(B: BuilderRef,
1279                          LHS: ValueRef,
1280                          RHS: ValueRef,
1281                          Name: *const c_char)
1282                          -> ValueRef;
1283     pub fn LLVMBuildExactSDiv(B: BuilderRef,
1284                               LHS: ValueRef,
1285                               RHS: ValueRef,
1286                               Name: *const c_char)
1287                               -> ValueRef;
1288     pub fn LLVMBuildFDiv(B: BuilderRef,
1289                          LHS: ValueRef,
1290                          RHS: ValueRef,
1291                          Name: *const c_char)
1292                          -> ValueRef;
1293     pub fn LLVMBuildURem(B: BuilderRef,
1294                          LHS: ValueRef,
1295                          RHS: ValueRef,
1296                          Name: *const c_char)
1297                          -> ValueRef;
1298     pub fn LLVMBuildSRem(B: BuilderRef,
1299                          LHS: ValueRef,
1300                          RHS: ValueRef,
1301                          Name: *const c_char)
1302                          -> ValueRef;
1303     pub fn LLVMBuildFRem(B: BuilderRef,
1304                          LHS: ValueRef,
1305                          RHS: ValueRef,
1306                          Name: *const c_char)
1307                          -> ValueRef;
1308     pub fn LLVMBuildShl(B: BuilderRef,
1309                         LHS: ValueRef,
1310                         RHS: ValueRef,
1311                         Name: *const c_char)
1312                         -> ValueRef;
1313     pub fn LLVMBuildLShr(B: BuilderRef,
1314                          LHS: ValueRef,
1315                          RHS: ValueRef,
1316                          Name: *const c_char)
1317                          -> ValueRef;
1318     pub fn LLVMBuildAShr(B: BuilderRef,
1319                          LHS: ValueRef,
1320                          RHS: ValueRef,
1321                          Name: *const c_char)
1322                          -> ValueRef;
1323     pub fn LLVMBuildAnd(B: BuilderRef,
1324                         LHS: ValueRef,
1325                         RHS: ValueRef,
1326                         Name: *const c_char)
1327                         -> ValueRef;
1328     pub fn LLVMBuildOr(B: BuilderRef,
1329                        LHS: ValueRef,
1330                        RHS: ValueRef,
1331                        Name: *const c_char)
1332                            -> ValueRef;
1333     pub fn LLVMBuildXor(B: BuilderRef,
1334                         LHS: ValueRef,
1335                         RHS: ValueRef,
1336                         Name: *const c_char)
1337                         -> ValueRef;
1338     pub fn LLVMBuildBinOp(B: BuilderRef,
1339                           Op: Opcode,
1340                           LHS: ValueRef,
1341                           RHS: ValueRef,
1342                           Name: *const c_char)
1343                           -> ValueRef;
1344     pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1345                         -> ValueRef;
1346     pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1347                            -> ValueRef;
1348     pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1349                            -> ValueRef;
1350     pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1351                          -> ValueRef;
1352     pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1353                         -> ValueRef;
1354
1355     /* Memory */
1356     pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1357                            -> ValueRef;
1358     pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1359     pub fn LLVMBuildLoad(B: BuilderRef,
1360                          PointerVal: ValueRef,
1361                          Name: *const c_char)
1362                          -> ValueRef;
1363
1364     pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1365                           -> ValueRef;
1366
1367     pub fn LLVMBuildGEP(B: BuilderRef,
1368                         Pointer: ValueRef,
1369                         Indices: *const ValueRef,
1370                         NumIndices: c_uint,
1371                         Name: *const c_char)
1372                         -> ValueRef;
1373     pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1374                                 Pointer: ValueRef,
1375                                 Indices: *const ValueRef,
1376                                 NumIndices: c_uint,
1377                                 Name: *const c_char)
1378                                 -> ValueRef;
1379     pub fn LLVMBuildStructGEP(B: BuilderRef,
1380                               Pointer: ValueRef,
1381                               Idx: c_uint,
1382                               Name: *const c_char)
1383                               -> ValueRef;
1384     pub fn LLVMBuildGlobalString(B: BuilderRef,
1385                                  Str: *const c_char,
1386                                  Name: *const c_char)
1387                                  -> ValueRef;
1388     pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1389                                     Str: *const c_char,
1390                                     Name: *const c_char)
1391                                     -> ValueRef;
1392
1393     /* Casts */
1394     pub fn LLVMBuildTrunc(B: BuilderRef,
1395                           Val: ValueRef,
1396                           DestTy: TypeRef,
1397                           Name: *const c_char)
1398                           -> ValueRef;
1399     pub fn LLVMBuildZExt(B: BuilderRef,
1400                          Val: ValueRef,
1401                          DestTy: TypeRef,
1402                          Name: *const c_char)
1403                          -> ValueRef;
1404     pub fn LLVMBuildSExt(B: BuilderRef,
1405                          Val: ValueRef,
1406                          DestTy: TypeRef,
1407                          Name: *const c_char)
1408                          -> ValueRef;
1409     pub fn LLVMBuildFPToUI(B: BuilderRef,
1410                            Val: ValueRef,
1411                            DestTy: TypeRef,
1412                            Name: *const c_char)
1413                            -> ValueRef;
1414     pub fn LLVMBuildFPToSI(B: BuilderRef,
1415                            Val: ValueRef,
1416                            DestTy: TypeRef,
1417                            Name: *const c_char)
1418                            -> ValueRef;
1419     pub fn LLVMBuildUIToFP(B: BuilderRef,
1420                            Val: ValueRef,
1421                            DestTy: TypeRef,
1422                            Name: *const c_char)
1423                            -> ValueRef;
1424     pub fn LLVMBuildSIToFP(B: BuilderRef,
1425                            Val: ValueRef,
1426                            DestTy: TypeRef,
1427                            Name: *const c_char)
1428                            -> ValueRef;
1429     pub fn LLVMBuildFPTrunc(B: BuilderRef,
1430                             Val: ValueRef,
1431                             DestTy: TypeRef,
1432                             Name: *const c_char)
1433                             -> ValueRef;
1434     pub fn LLVMBuildFPExt(B: BuilderRef,
1435                           Val: ValueRef,
1436                           DestTy: TypeRef,
1437                           Name: *const c_char)
1438                           -> ValueRef;
1439     pub fn LLVMBuildPtrToInt(B: BuilderRef,
1440                              Val: ValueRef,
1441                              DestTy: TypeRef,
1442                              Name: *const c_char)
1443                              -> ValueRef;
1444     pub fn LLVMBuildIntToPtr(B: BuilderRef,
1445                              Val: ValueRef,
1446                              DestTy: TypeRef,
1447                              Name: *const c_char)
1448                              -> ValueRef;
1449     pub fn LLVMBuildBitCast(B: BuilderRef,
1450                             Val: ValueRef,
1451                             DestTy: TypeRef,
1452                             Name: *const c_char)
1453                             -> ValueRef;
1454     pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1455                                   Val: ValueRef,
1456                                   DestTy: TypeRef,
1457                                   Name: *const c_char)
1458                                   -> ValueRef;
1459     pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1460                                   Val: ValueRef,
1461                                   DestTy: TypeRef,
1462                                   Name: *const c_char)
1463                                   -> ValueRef;
1464     pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1465                                    Val: ValueRef,
1466                                    DestTy: TypeRef,
1467                                    Name: *const c_char)
1468                                    -> ValueRef;
1469     pub fn LLVMBuildCast(B: BuilderRef,
1470                          Op: Opcode,
1471                          Val: ValueRef,
1472                          DestTy: TypeRef,
1473                          Name: *const c_char) -> ValueRef;
1474     pub fn LLVMBuildPointerCast(B: BuilderRef,
1475                                 Val: ValueRef,
1476                                 DestTy: TypeRef,
1477                                 Name: *const c_char)
1478                                 -> ValueRef;
1479     pub fn LLVMBuildIntCast(B: BuilderRef,
1480                             Val: ValueRef,
1481                             DestTy: TypeRef,
1482                             Name: *const c_char)
1483                             -> ValueRef;
1484     pub fn LLVMBuildFPCast(B: BuilderRef,
1485                            Val: ValueRef,
1486                            DestTy: TypeRef,
1487                            Name: *const c_char)
1488                            -> ValueRef;
1489
1490     /* Comparisons */
1491     pub fn LLVMBuildICmp(B: BuilderRef,
1492                          Op: c_uint,
1493                          LHS: ValueRef,
1494                          RHS: ValueRef,
1495                          Name: *const c_char)
1496                          -> ValueRef;
1497     pub fn LLVMBuildFCmp(B: BuilderRef,
1498                          Op: c_uint,
1499                          LHS: ValueRef,
1500                          RHS: ValueRef,
1501                          Name: *const c_char)
1502                          -> ValueRef;
1503
1504     /* Miscellaneous instructions */
1505     pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1506                         -> ValueRef;
1507     pub fn LLVMRustBuildCall(B: BuilderRef,
1508                              Fn: ValueRef,
1509                              Args: *const ValueRef,
1510                              NumArgs: c_uint,
1511                              Bundle: OperandBundleDefRef,
1512                              Name: *const c_char)
1513                              -> ValueRef;
1514     pub fn LLVMBuildSelect(B: BuilderRef,
1515                            If: ValueRef,
1516                            Then: ValueRef,
1517                            Else: ValueRef,
1518                            Name: *const c_char)
1519                            -> ValueRef;
1520     pub fn LLVMBuildVAArg(B: BuilderRef,
1521                           list: ValueRef,
1522                           Ty: TypeRef,
1523                           Name: *const c_char)
1524                           -> ValueRef;
1525     pub fn LLVMBuildExtractElement(B: BuilderRef,
1526                                    VecVal: ValueRef,
1527                                    Index: ValueRef,
1528                                    Name: *const c_char)
1529                                    -> ValueRef;
1530     pub fn LLVMBuildInsertElement(B: BuilderRef,
1531                                   VecVal: ValueRef,
1532                                   EltVal: ValueRef,
1533                                   Index: ValueRef,
1534                                   Name: *const c_char)
1535                                   -> ValueRef;
1536     pub fn LLVMBuildShuffleVector(B: BuilderRef,
1537                                   V1: ValueRef,
1538                                   V2: ValueRef,
1539                                   Mask: ValueRef,
1540                                   Name: *const c_char)
1541                                   -> ValueRef;
1542     pub fn LLVMBuildExtractValue(B: BuilderRef,
1543                                  AggVal: ValueRef,
1544                                  Index: c_uint,
1545                                  Name: *const c_char)
1546                                  -> ValueRef;
1547     pub fn LLVMBuildInsertValue(B: BuilderRef,
1548                                 AggVal: ValueRef,
1549                                 EltVal: ValueRef,
1550                                 Index: c_uint,
1551                                 Name: *const c_char)
1552                                 -> ValueRef;
1553
1554     pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1555                            -> ValueRef;
1556     pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1557                               -> ValueRef;
1558     pub fn LLVMBuildPtrDiff(B: BuilderRef,
1559                             LHS: ValueRef,
1560                             RHS: ValueRef,
1561                             Name: *const c_char)
1562                             -> ValueRef;
1563
1564     /* Atomic Operations */
1565     pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1566                                PointerVal: ValueRef,
1567                                Name: *const c_char,
1568                                Order: AtomicOrdering,
1569                                Alignment: c_uint)
1570                                -> ValueRef;
1571
1572     pub fn LLVMBuildAtomicStore(B: BuilderRef,
1573                                 Val: ValueRef,
1574                                 Ptr: ValueRef,
1575                                 Order: AtomicOrdering,
1576                                 Alignment: c_uint)
1577                                 -> ValueRef;
1578
1579     pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1580                                   LHS: ValueRef,
1581                                   CMP: ValueRef,
1582                                   RHS: ValueRef,
1583                                   Order: AtomicOrdering,
1584                                   FailureOrder: AtomicOrdering)
1585                                   -> ValueRef;
1586     pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1587                               Op: AtomicBinOp,
1588                               LHS: ValueRef,
1589                               RHS: ValueRef,
1590                               Order: AtomicOrdering,
1591                               SingleThreaded: Bool)
1592                               -> ValueRef;
1593
1594     pub fn LLVMBuildAtomicFence(B: BuilderRef,
1595                                 Order: AtomicOrdering,
1596                                 Scope: SynchronizationScope);
1597
1598
1599     /* Selected entries from the downcasts. */
1600     pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1601     pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1602
1603     /// Writes a module to the specified path. Returns 0 on success.
1604     pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1605
1606     /// Creates target data from a target layout string.
1607     pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1608     /// Adds the target data to the given pass manager. The pass manager
1609     /// references the target data only weakly.
1610     pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1611     /// Number of bytes clobbered when doing a Store to *T.
1612     pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1613                                -> c_ulonglong;
1614
1615     /// Number of bytes clobbered when doing a Store to *T.
1616     pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1617                                 -> c_ulonglong;
1618
1619     /// Distance between successive elements in an array of T. Includes ABI padding.
1620     pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1621
1622     /// Returns the preferred alignment of a type.
1623     pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1624                                         -> c_uint;
1625     /// Returns the minimum alignment of a type.
1626     pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1627                                   -> c_uint;
1628
1629     /// Computes the byte offset of the indexed struct element for a
1630     /// target.
1631     pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1632                                StructTy: TypeRef,
1633                                Element: c_uint)
1634                                -> c_ulonglong;
1635
1636     /// Returns the minimum alignment of a type when part of a call frame.
1637     pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1638                                         -> c_uint;
1639
1640     /// Disposes target data.
1641     pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1642
1643     /// Creates a pass manager.
1644     pub fn LLVMCreatePassManager() -> PassManagerRef;
1645
1646     /// Creates a function-by-function pass manager
1647     pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1648                                                   -> PassManagerRef;
1649
1650     /// Disposes a pass manager.
1651     pub fn LLVMDisposePassManager(PM: PassManagerRef);
1652
1653     /// Runs a pass manager on a module.
1654     pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1655
1656     /// Runs the function passes on the provided function.
1657     pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1658                                       -> Bool;
1659
1660     /// Initializes all the function passes scheduled in the manager
1661     pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1662
1663     /// Finalizes all the function passes scheduled in the manager
1664     pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1665
1666     pub fn LLVMInitializePasses();
1667
1668     /// Adds a verification pass.
1669     pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1670
1671     pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1672     pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1673     pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1674     pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1675     pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1676     pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1677     pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1678     pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1679     pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1680     pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1681     pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1682     pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1683     pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1684     pub fn LLVMAddLICMPass(PM: PassManagerRef);
1685     pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1686     pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1687     pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1688     pub fn LLVMAddGVNPass(PM: PassManagerRef);
1689     pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1690     pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1691     pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1692     pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1693     pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1694     pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1695     pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1696     pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1697     pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1698     pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1699     pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1700     pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1701     pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1702     pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1703     pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1704     pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1705     pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1706
1707     pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1708     pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1709     pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1710                                              OptimizationLevel: c_uint);
1711     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1712                                               Value: Bool);
1713     pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1714         PMB: PassManagerBuilderRef,
1715         Value: Bool);
1716     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1717         PMB: PassManagerBuilderRef,
1718         Value: Bool);
1719     pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1720         PMB: PassManagerBuilderRef,
1721         Value: Bool);
1722     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1723         PMB: PassManagerBuilderRef,
1724         threshold: c_uint);
1725     pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1726         PMB: PassManagerBuilderRef,
1727         PM: PassManagerRef);
1728
1729     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1730         PMB: PassManagerBuilderRef,
1731         PM: PassManagerRef);
1732     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1733         PMB: PassManagerBuilderRef,
1734         PM: PassManagerRef,
1735         Internalize: Bool,
1736         RunInliner: Bool);
1737
1738     /// Destroys a memory buffer.
1739     pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1740
1741
1742     /* Stuff that's in rustllvm/ because it's not upstream yet. */
1743
1744     /// Opens an object file.
1745     pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1746     /// Closes an object file.
1747     pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1748
1749     /// Enumerates the sections in an object file.
1750     pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1751     /// Destroys a section iterator.
1752     pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1753     /// Returns true if the section iterator is at the end of the section
1754     /// list:
1755     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1756                                       SI: SectionIteratorRef)
1757                                       -> Bool;
1758     /// Moves the section iterator to point to the next section.
1759     pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1760     /// Returns the current section size.
1761     pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1762     /// Returns the current section contents as a string buffer.
1763     pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1764
1765     /// Reads the given file and returns it as a memory buffer. Use
1766     /// LLVMDisposeMemoryBuffer() to get rid of it.
1767     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1768                                                         -> MemoryBufferRef;
1769     /// Borrows the contents of the memory buffer (doesn't copy it)
1770     pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1771                                                  InputDataLength: size_t,
1772                                                  BufferName: *const c_char,
1773                                                  RequiresNull: Bool)
1774                                                  -> MemoryBufferRef;
1775     pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1776                                                      InputDataLength: size_t,
1777                                                      BufferName: *const c_char)
1778                                                      -> MemoryBufferRef;
1779
1780     pub fn LLVMIsMultithreaded() -> Bool;
1781     pub fn LLVMStartMultithreaded() -> Bool;
1782
1783     /// Returns a string describing the last error caused by an LLVMRust* call.
1784     pub fn LLVMRustGetLastError() -> *const c_char;
1785
1786     /// Print the pass timings since static dtors aren't picking them up.
1787     pub fn LLVMRustPrintPassTimings();
1788
1789     pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1790
1791     pub fn LLVMStructSetBody(StructTy: TypeRef,
1792                              ElementTypes: *const TypeRef,
1793                              ElementCount: c_uint,
1794                              Packed: Bool);
1795
1796     pub fn LLVMConstNamedStruct(S: TypeRef,
1797                                 ConstantVals: *const ValueRef,
1798                                 Count: c_uint)
1799                                 -> ValueRef;
1800
1801     /// Enables LLVM debug output.
1802     pub fn LLVMSetDebug(Enabled: c_int);
1803
1804     /// Prepares inline assembly.
1805     pub fn LLVMInlineAsm(Ty: TypeRef,
1806                          AsmString: *const c_char,
1807                          Constraints: *const c_char,
1808                          SideEffects: Bool,
1809                          AlignStack: Bool,
1810                          Dialect: c_uint)
1811                          -> ValueRef;
1812
1813     pub fn LLVMRustDebugMetadataVersion() -> u32;
1814     pub fn LLVMVersionMajor() -> u32;
1815     pub fn LLVMVersionMinor() -> u32;
1816
1817     pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1818                                  name: *const c_char,
1819                                  value: u32);
1820
1821     pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1822
1823     pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1824
1825     pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1826
1827     pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1828                                           Lang: c_uint,
1829                                           File: *const c_char,
1830                                           Dir: *const c_char,
1831                                           Producer: *const c_char,
1832                                           isOptimized: bool,
1833                                           Flags: *const c_char,
1834                                           RuntimeVer: c_uint,
1835                                           SplitName: *const c_char)
1836                                           -> DIDescriptor;
1837
1838     pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1839                                    Filename: *const c_char,
1840                                    Directory: *const c_char)
1841                                    -> DIFile;
1842
1843     pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1844                                              File: DIFile,
1845                                              ParameterTypes: DIArray)
1846                                              -> DICompositeType;
1847
1848     pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1849                                        Scope: DIDescriptor,
1850                                        Name: *const c_char,
1851                                        LinkageName: *const c_char,
1852                                        File: DIFile,
1853                                        LineNo: c_uint,
1854                                        Ty: DIType,
1855                                        isLocalToUnit: bool,
1856                                        isDefinition: bool,
1857                                        ScopeLine: c_uint,
1858                                        Flags: c_uint,
1859                                        isOptimized: bool,
1860                                        Fn: ValueRef,
1861                                        TParam: DIArray,
1862                                        Decl: DIDescriptor)
1863                                        -> DISubprogram;
1864
1865     pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1866                                         Name: *const c_char,
1867                                         SizeInBits: c_ulonglong,
1868                                         AlignInBits: c_ulonglong,
1869                                         Encoding: c_uint)
1870                                         -> DIBasicType;
1871
1872     pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1873                                           PointeeTy: DIType,
1874                                           SizeInBits: c_ulonglong,
1875                                           AlignInBits: c_ulonglong,
1876                                           Name: *const c_char)
1877                                           -> DIDerivedType;
1878
1879     pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1880                                          Scope: DIDescriptor,
1881                                          Name: *const c_char,
1882                                          File: DIFile,
1883                                          LineNumber: c_uint,
1884                                          SizeInBits: c_ulonglong,
1885                                          AlignInBits: c_ulonglong,
1886                                          Flags: c_uint,
1887                                          DerivedFrom: DIType,
1888                                          Elements: DIArray,
1889                                          RunTimeLang: c_uint,
1890                                          VTableHolder: DIType,
1891                                          UniqueId: *const c_char)
1892                                          -> DICompositeType;
1893
1894     pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1895                                          Scope: DIDescriptor,
1896                                          Name: *const c_char,
1897                                          File: DIFile,
1898                                          LineNo: c_uint,
1899                                          SizeInBits: c_ulonglong,
1900                                          AlignInBits: c_ulonglong,
1901                                          OffsetInBits: c_ulonglong,
1902                                          Flags: c_uint,
1903                                          Ty: DIType)
1904                                          -> DIDerivedType;
1905
1906     pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1907                                            Scope: DIScope,
1908                                            File: DIFile,
1909                                            Line: c_uint,
1910                                            Col: c_uint)
1911                                            -> DILexicalBlock;
1912
1913     pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1914                                              Context: DIScope,
1915                                              Name: *const c_char,
1916                                              LinkageName: *const c_char,
1917                                              File: DIFile,
1918                                              LineNo: c_uint,
1919                                              Ty: DIType,
1920                                              isLocalToUnit: bool,
1921                                              Val: ValueRef,
1922                                              Decl: DIDescriptor)
1923                                              -> DIGlobalVariable;
1924
1925     pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1926                                             Tag: c_uint,
1927                                             Scope: DIDescriptor,
1928                                             Name: *const c_char,
1929                                             File: DIFile,
1930                                             LineNo: c_uint,
1931                                             Ty: DIType,
1932                                             AlwaysPreserve: bool,
1933                                             Flags: c_uint,
1934                                             AddrOps: *const i64,
1935                                             AddrOpsCount: c_uint,
1936                                             ArgNo: c_uint)
1937                                             -> DIVariable;
1938
1939     pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1940                                         Size: c_ulonglong,
1941                                         AlignInBits: c_ulonglong,
1942                                         Ty: DIType,
1943                                         Subscripts: DIArray)
1944                                         -> DIType;
1945
1946     pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1947                                          Size: c_ulonglong,
1948                                          AlignInBits: c_ulonglong,
1949                                          Ty: DIType,
1950                                          Subscripts: DIArray)
1951                                          -> DIType;
1952
1953     pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1954                                             Lo: c_longlong,
1955                                             Count: c_longlong)
1956                                             -> DISubrange;
1957
1958     pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1959                                          Ptr: *const DIDescriptor,
1960                                          Count: c_uint)
1961                                          -> DIArray;
1962
1963     pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1964                                            Val: ValueRef,
1965                                            VarInfo: DIVariable,
1966                                            AddrOps: *const i64,
1967                                            AddrOpsCount: c_uint,
1968                                            DL: ValueRef,
1969                                            InsertAtEnd: BasicBlockRef)
1970                                            -> ValueRef;
1971
1972     pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1973                                             Val: ValueRef,
1974                                             VarInfo: DIVariable,
1975                                             AddrOps: *const i64,
1976                                             AddrOpsCount: c_uint,
1977                                             DL: ValueRef,
1978                                             InsertBefore: ValueRef)
1979                                             -> ValueRef;
1980
1981     pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1982                                          Name: *const c_char,
1983                                          Val: c_ulonglong)
1984                                          -> DIEnumerator;
1985
1986     pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1987                                               Scope: DIScope,
1988                                               Name: *const c_char,
1989                                               File: DIFile,
1990                                               LineNumber: c_uint,
1991                                               SizeInBits: c_ulonglong,
1992                                               AlignInBits: c_ulonglong,
1993                                               Elements: DIArray,
1994                                               ClassType: DIType)
1995                                               -> DIType;
1996
1997     pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1998                                         Scope: DIScope,
1999                                         Name: *const c_char,
2000                                         File: DIFile,
2001                                         LineNumber: c_uint,
2002                                         SizeInBits: c_ulonglong,
2003                                         AlignInBits: c_ulonglong,
2004                                         Flags: c_uint,
2005                                         Elements: DIArray,
2006                                         RunTimeLang: c_uint,
2007                                         UniqueId: *const c_char)
2008                                         -> DIType;
2009
2010     pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
2011
2012     pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
2013                                                     Scope: DIScope,
2014                                                     Name: *const c_char,
2015                                                     Ty: DIType,
2016                                                     File: DIFile,
2017                                                     LineNo: c_uint,
2018                                                     ColumnNo: c_uint)
2019                                                     -> DITemplateTypeParameter;
2020
2021     pub fn LLVMDIBuilderCreateOpDeref() -> i64;
2022
2023     pub fn LLVMDIBuilderCreateOpPlus() -> i64;
2024
2025     pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
2026                                         Scope: DIScope,
2027                                         Name: *const c_char,
2028                                         File: DIFile,
2029                                         LineNo: c_uint)
2030                                         -> DINameSpace;
2031
2032     pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
2033                                             Line: c_uint,
2034                                             Column: c_uint,
2035                                             Scope: DIScope,
2036                                             InlinedAt: MetadataRef)
2037                                             -> ValueRef;
2038
2039     pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2040                                            CompositeType: DIType,
2041                                            TypeArray: DIArray);
2042     pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2043     pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2044
2045     pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2046
2047     pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2048     pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2049
2050     pub fn LLVMRustPassKind(Pass: PassRef) -> SupportedPassKind;
2051     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
2052     pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);
2053
2054     pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2055                                        CPU: *const c_char,
2056                                        Features: *const c_char,
2057                                        Model: CodeGenModel,
2058                                        Reloc: RelocMode,
2059                                        Level: CodeGenOptLevel,
2060                                        UseSoftFP: bool,
2061                                        PositionIndependentExecutable: bool,
2062                                        FunctionSections: bool,
2063                                        DataSections: bool) -> TargetMachineRef;
2064     pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2065     pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2066                                      PM: PassManagerRef,
2067                                      M: ModuleRef);
2068     pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2069                                          M: ModuleRef,
2070                                          DisableSimplifyLibCalls: bool);
2071     pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2072                                                OptLevel: CodeGenOptLevel,
2073                                                MergeFunctions: bool,
2074                                                SLPVectorize: bool,
2075                                                LoopVectorize: bool);
2076     pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2077                                   DisableSimplifyLibCalls: bool);
2078     pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2079     pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2080                                    PM: PassManagerRef,
2081                                    M: ModuleRef,
2082                                    Output: *const c_char,
2083                                    FileType: FileType) -> bool;
2084     pub fn LLVMRustPrintModule(PM: PassManagerRef,
2085                                M: ModuleRef,
2086                                Output: *const c_char);
2087     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2088     pub fn LLVMRustPrintPasses();
2089     pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2090     pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2091                                        AddLifetimes: bool);
2092     pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2093                                          bc: *const c_char,
2094                                          len: size_t) -> bool;
2095     pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2096                                       syms: *const *const c_char,
2097                                       len: size_t);
2098     pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2099
2100     pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2101     pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2102     pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2103     pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2104                                     size: *mut size_t) -> *const c_char;
2105     pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2106                                     size: *mut size_t) -> *const c_char;
2107     pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2108     pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2109     pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2110
2111     pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2112                                       C: DLLStorageClassTypes);
2113
2114     pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2115                                   data: *mut *const c_char) -> c_int;
2116
2117     pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2118
2119     pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2120                                            Handler: DiagnosticHandler,
2121                                            DiagnosticContext: *mut c_void);
2122
2123     pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2124                                             pass_name_out: *mut *const c_char,
2125                                             function_out: *mut ValueRef,
2126                                             debugloc_out: *mut DebugLocRef,
2127                                             message_out: *mut TwineRef);
2128     pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2129                                             cookie_out: *mut c_uint,
2130                                             message_out: *mut TwineRef,
2131                                             instruction_out: *mut ValueRef);
2132
2133     pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2134     pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2135     pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2136
2137     pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2138
2139     pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2140                                              H: InlineAsmDiagHandler,
2141                                              CX: *mut c_void);
2142
2143     pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2144
2145     pub fn LLVMRustWriteArchive(Dst: *const c_char,
2146                                 NumMembers: size_t,
2147                                 Members: *const RustArchiveMemberRef,
2148                                 WriteSymbtab: bool,
2149                                 Kind: ArchiveKind) -> c_int;
2150     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2151                                     Name: *const c_char,
2152                                     Child: ArchiveChildRef) -> RustArchiveMemberRef;
2153     pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2154
2155     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2156                                                   TM: TargetMachineRef);
2157     pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2158
2159     pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
2160                                          Inputs: *const ValueRef,
2161                                          NumInputs: c_uint)
2162                                          -> OperandBundleDefRef;
2163     pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
2164 }
2165
2166 #[cfg(have_component_x86)]
2167 extern {
2168     pub fn LLVMInitializeX86TargetInfo();
2169     pub fn LLVMInitializeX86Target();
2170     pub fn LLVMInitializeX86TargetMC();
2171     pub fn LLVMInitializeX86AsmPrinter();
2172     pub fn LLVMInitializeX86AsmParser();
2173 }
2174 #[cfg(have_component_arm)]
2175 extern {
2176     pub fn LLVMInitializeARMTargetInfo();
2177     pub fn LLVMInitializeARMTarget();
2178     pub fn LLVMInitializeARMTargetMC();
2179     pub fn LLVMInitializeARMAsmPrinter();
2180     pub fn LLVMInitializeARMAsmParser();
2181 }
2182 #[cfg(have_component_aarch64)]
2183 extern {
2184     pub fn LLVMInitializeAArch64TargetInfo();
2185     pub fn LLVMInitializeAArch64Target();
2186     pub fn LLVMInitializeAArch64TargetMC();
2187     pub fn LLVMInitializeAArch64AsmPrinter();
2188     pub fn LLVMInitializeAArch64AsmParser();
2189 }
2190 #[cfg(have_component_mips)]
2191 extern {
2192     pub fn LLVMInitializeMipsTargetInfo();
2193     pub fn LLVMInitializeMipsTarget();
2194     pub fn LLVMInitializeMipsTargetMC();
2195     pub fn LLVMInitializeMipsAsmPrinter();
2196     pub fn LLVMInitializeMipsAsmParser();
2197 }
2198 #[cfg(have_component_powerpc)]
2199 extern {
2200     pub fn LLVMInitializePowerPCTargetInfo();
2201     pub fn LLVMInitializePowerPCTarget();
2202     pub fn LLVMInitializePowerPCTargetMC();
2203     pub fn LLVMInitializePowerPCAsmPrinter();
2204     pub fn LLVMInitializePowerPCAsmParser();
2205 }
2206 #[cfg(have_component_pnacl)]
2207 extern {
2208     pub fn LLVMInitializePNaClTargetInfo();
2209     pub fn LLVMInitializePNaClTarget();
2210     pub fn LLVMInitializePNaClTargetMC();
2211 }
2212
2213 // LLVM requires symbols from this library, but apparently they're not printed
2214 // during llvm-config?
2215 #[cfg(windows)]
2216 #[link(name = "ole32")]
2217 extern {}
2218
2219 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2220     unsafe {
2221         LLVMSetInstructionCallConv(instr, cc as c_uint);
2222     }
2223 }
2224 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2225     unsafe {
2226         LLVMSetFunctionCallConv(fn_, cc as c_uint);
2227     }
2228 }
2229 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2230     unsafe {
2231         LLVMSetLinkage(global, link as c_uint);
2232     }
2233 }
2234
2235 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2236     unsafe {
2237         LLVMRustSetDLLStorageClass(global, class);
2238     }
2239 }
2240
2241 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2242     unsafe {
2243         LLVMSetUnnamedAddr(global, unnamed as Bool);
2244     }
2245 }
2246
2247 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2248     unsafe {
2249         LLVMSetThreadLocal(global, is_thread_local as Bool);
2250     }
2251 }
2252
2253 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2254     unsafe {
2255         LLVMConstICmp(pred as c_ushort, v1, v2)
2256     }
2257 }
2258 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2259     unsafe {
2260         LLVMConstFCmp(pred as c_ushort, v1, v2)
2261     }
2262 }
2263
2264 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2265     unsafe {
2266         LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2267                                  attr.bits() as uint64_t)
2268     }
2269 }
2270
2271 /* Memory-managed interface to target data. */
2272
2273 pub struct TargetData {
2274     pub lltd: TargetDataRef
2275 }
2276
2277 impl Drop for TargetData {
2278     fn drop(&mut self) {
2279         unsafe {
2280             LLVMDisposeTargetData(self.lltd);
2281         }
2282     }
2283 }
2284
2285 pub fn mk_target_data(string_rep: &str) -> TargetData {
2286     let string_rep = CString::new(string_rep).unwrap();
2287     TargetData {
2288         lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2289     }
2290 }
2291
2292 /* Memory-managed interface to object files. */
2293
2294 pub struct ObjectFile {
2295     pub llof: ObjectFileRef,
2296 }
2297
2298 impl ObjectFile {
2299     // This will take ownership of llmb
2300     pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2301         unsafe {
2302             let llof = LLVMCreateObjectFile(llmb);
2303             if llof as isize == 0 {
2304                 // LLVMCreateObjectFile took ownership of llmb
2305                 return None
2306             }
2307
2308             Some(ObjectFile {
2309                 llof: llof,
2310             })
2311         }
2312     }
2313 }
2314
2315 impl Drop for ObjectFile {
2316     fn drop(&mut self) {
2317         unsafe {
2318             LLVMDisposeObjectFile(self.llof);
2319         }
2320     }
2321 }
2322
2323 /* Memory-managed interface to section iterators. */
2324
2325 pub struct SectionIter {
2326     pub llsi: SectionIteratorRef
2327 }
2328
2329 impl Drop for SectionIter {
2330     fn drop(&mut self) {
2331         unsafe {
2332             LLVMDisposeSectionIterator(self.llsi);
2333         }
2334     }
2335 }
2336
2337 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2338     unsafe {
2339         SectionIter {
2340             llsi: LLVMGetSections(llof)
2341         }
2342     }
2343 }
2344
2345 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2346 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2347     unsafe {
2348         assert!(index < LLVMCountParams(llfn));
2349         LLVMGetParam(llfn, index)
2350     }
2351 }
2352
2353 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2354     unsafe {
2355         let num_params = LLVMCountParams(llfn);
2356         let mut params = Vec::with_capacity(num_params as usize);
2357         for idx in 0..num_params {
2358             params.push(LLVMGetParam(llfn, idx));
2359         }
2360
2361         params
2362     }
2363 }
2364
2365 #[allow(missing_copy_implementations)]
2366 pub enum RustString_opaque {}
2367 pub type RustStringRef = *mut RustString_opaque;
2368 type RustStringRepr = *mut RefCell<Vec<u8>>;
2369
2370 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2371 #[no_mangle]
2372 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2373                                                      ptr: *const c_char,
2374                                                      size: size_t) {
2375     let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2376
2377     let sr = sr as RustStringRepr;
2378     (*sr).borrow_mut().extend_from_slice(slice);
2379 }
2380
2381 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2382     let mut buf = RefCell::new(Vec::new());
2383     f(&mut buf as RustStringRepr as RustStringRef);
2384     String::from_utf8(buf.into_inner()).ok()
2385 }
2386
2387 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2388     build_string(|s| LLVMWriteTwineToString(tr, s))
2389         .expect("got a non-UTF8 Twine from LLVM")
2390 }
2391
2392 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2393     build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2394         .expect("got a non-UTF8 DebugLoc from LLVM")
2395 }
2396
2397 pub fn initialize_available_targets() {
2398     macro_rules! init_target(
2399         ($cfg:ident $arch:ident) => { {
2400             #[cfg($cfg)]
2401             fn init() {
2402                 unsafe {
2403                     let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2404                     f();
2405                     let f = concat_idents!(LLVMInitialize, $arch, Target);
2406                     f();
2407                     let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2408                     f();
2409                     let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2410                     f();
2411                     let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2412                     f();
2413                 }
2414             }
2415             #[cfg(not($cfg))]
2416             fn init() { }
2417             init();
2418         } }
2419     );
2420
2421     init_target!(have_component_powerpc PowerPC);
2422     init_target!(have_component_mips Mips);
2423     init_target!(have_component_aarch64 AArch64);
2424     init_target!(have_component_arm ARM);
2425     init_target!(have_component_x86 X86);
2426
2427     // PNaCl doesn't provide some of the optional target components, so we
2428     // manually initialize it here.
2429     #[cfg(have_component_pnacl)]
2430     fn init_pnacl() {
2431         unsafe {
2432             LLVMInitializePNaClTargetInfo();
2433             LLVMInitializePNaClTarget();
2434             LLVMInitializePNaClTargetMC();
2435         }
2436     }
2437     #[cfg(not(have_component_pnacl))]
2438     fn init_pnacl() { }
2439     init_pnacl();
2440 }
2441
2442 pub fn last_error() -> Option<String> {
2443     unsafe {
2444         let cstr = LLVMRustGetLastError();
2445         if cstr.is_null() {
2446             None
2447         } else {
2448             let err = CStr::from_ptr(cstr).to_bytes();
2449             let err = String::from_utf8_lossy(err).to_string();
2450             libc::free(cstr as *mut _);
2451             Some(err)
2452         }
2453     }
2454 }
2455
2456 pub struct OperandBundleDef {
2457     inner: OperandBundleDefRef,
2458 }
2459
2460 impl OperandBundleDef {
2461     pub fn new(name: &str, vals: &[ValueRef]) -> OperandBundleDef {
2462         let name = CString::new(name).unwrap();
2463         let def = unsafe {
2464             LLVMRustBuildOperandBundleDef(name.as_ptr(),
2465                                           vals.as_ptr(),
2466                                           vals.len() as c_uint)
2467         };
2468         OperandBundleDef { inner: def }
2469     }
2470
2471     pub fn raw(&self) -> OperandBundleDefRef {
2472         self.inner
2473     }
2474 }
2475
2476 impl Drop for OperandBundleDef {
2477     fn drop(&mut self) {
2478         unsafe {
2479             LLVMRustFreeOperandBundleDef(self.inner);
2480         }
2481     }
2482 }
2483
2484 // The module containing the native LLVM dependencies, generated by the build system
2485 // Note that this must come after the rustllvm extern declaration so that
2486 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2487 // Works to the above fix for #15460 to ensure LLVM dependencies that
2488 // are only used by rustllvm don't get stripped by the linker.
2489 mod llvmdeps {
2490     include! { env!("CFG_LLVM_LINKAGE_FILE") }
2491 }