about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2016-08-02 02:35:09 +0300
committerAriel Ben-Yehuda <arielb1@mail.tau.ac.il>2016-08-03 15:08:47 +0300
commitd091ef802f5aa6d5b81e711ecd7e5f66a76b01a9 (patch)
tree6dc5665c8e39d3503a0ef19bcea9f39c92738cd5 /src
parent696691e3c4f2b3aa02fbd1cc76dc2f7e8a401db8 (diff)
downloadrust-d091ef802f5aa6d5b81e711ecd7e5f66a76b01a9.tar.gz
rust-d091ef802f5aa6d5b81e711ecd7e5f66a76b01a9.zip
begin auditing the C++ types in RustWrapper
Diffstat (limited to 'src')
-rw-r--r--src/librustc_driver/lib.rs2
-rw-r--r--src/librustc_llvm/diagnostic.rs55
-rw-r--r--src/librustc_llvm/lib.rs628
-rw-r--r--src/librustc_trans/attributes.rs8
-rw-r--r--src/librustc_trans/back/write.rs4
-rw-r--r--src/librustc_trans/base.rs3
-rw-r--r--src/librustc_trans/builder.rs10
-rw-r--r--src/librustc_trans/consts.rs4
-rw-r--r--src/librustc_trans/debuginfo/create_scope_map.rs6
-rw-r--r--src/librustc_trans/debuginfo/metadata.rs67
-rw-r--r--src/librustc_trans/debuginfo/mod.rs16
-rw-r--r--src/librustc_trans/debuginfo/namespace.rs2
-rw-r--r--src/librustc_trans/debuginfo/source_loc.rs2
-rw-r--r--src/librustc_trans/debuginfo/utils.rs2
-rw-r--r--src/librustc_trans/declare.rs6
-rw-r--r--src/librustc_trans/intrinsic.rs26
-rw-r--r--src/librustc_trans/mir/mod.rs10
-rw-r--r--src/librustc_trans/type_.rs4
-rw-r--r--src/librustc_trans/value.rs2
-rw-r--r--src/rustllvm/RustWrapper.cpp516
20 files changed, 771 insertions, 602 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index f49d47fb081..772c59b34dd 100644
--- a/src/librustc_driver/lib.rs
+++ b/src/librustc_driver/lib.rs
@@ -186,7 +186,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
     let sopts = config::build_session_options(&matches);
 
     if sopts.debugging_opts.debug_llvm {
-        unsafe { llvm::LLVMSetDebug(1); }
+        unsafe { llvm::LLVMRustSetDebug(1); }
     }
 
     let descriptions = diagnostics_registry();
diff --git a/src/librustc_llvm/diagnostic.rs b/src/librustc_llvm/diagnostic.rs
index 44e01561464..4938a0216ee 100644
--- a/src/librustc_llvm/diagnostic.rs
+++ b/src/librustc_llvm/diagnostic.rs
@@ -23,15 +23,21 @@ pub enum OptimizationDiagnosticKind {
     OptimizationRemark,
     OptimizationMissed,
     OptimizationAnalysis,
+    OptimizationAnalysisFPCommute,
+    OptimizationAnalysisAliasing,
     OptimizationFailure,
+    OptimizationRemarkOther,
 }
 
 impl OptimizationDiagnosticKind {
     pub fn describe(self) -> &'static str {
         match self {
-            OptimizationRemark => "remark",
+            OptimizationRemark |
+            OptimizationRemarkOther => "remark",
             OptimizationMissed => "missed",
             OptimizationAnalysis => "analysis",
+            OptimizationAnalysisFPCommute => "floating-point",
+            OptimizationAnalysisAliasing => "aliasing",
             OptimizationFailure => "failure",
         }
     }
@@ -58,11 +64,11 @@ impl OptimizationDiagnostic {
             message: ptr::null_mut(),
         };
 
-        super::LLVMUnpackOptimizationDiagnostic(di,
-                                                &mut opt.pass_name,
-                                                &mut opt.function,
-                                                &mut opt.debug_loc,
-                                                &mut opt.message);
+        super::LLVMRustUnpackOptimizationDiagnostic(di,
+                                                    &mut opt.pass_name,
+                                                    &mut opt.function,
+                                                    &mut opt.debug_loc,
+                                                    &mut opt.message);
 
         opt
     }
@@ -84,10 +90,10 @@ impl InlineAsmDiagnostic {
             instruction: ptr::null_mut(),
         };
 
-        super::LLVMUnpackInlineAsmDiagnostic(di,
-                                             &mut opt.cookie,
-                                             &mut opt.message,
-                                             &mut opt.instruction);
+        super::LLVMRustUnpackInlineAsmDiagnostic(di,
+                                                 &mut opt.cookie,
+                                                 &mut opt.message,
+                                                 &mut opt.instruction);
 
         opt
     }
@@ -103,24 +109,39 @@ pub enum Diagnostic {
 
 impl Diagnostic {
     pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic {
-        let kind = super::LLVMGetDiagInfoKind(di);
+        use super::DiagnosticKind as Dk;
+        let kind = super::LLVMRustGetDiagInfoKind(di);
 
         match kind {
-            super::DK_InlineAsm => InlineAsm(InlineAsmDiagnostic::unpack(di)),
+            Dk::InlineAsm => InlineAsm(InlineAsmDiagnostic::unpack(di)),
 
-            super::DK_OptimizationRemark => {
+            Dk::OptimizationRemark => {
                 Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di))
             }
-
-            super::DK_OptimizationRemarkMissed => {
+            Dk::OptimizationRemarkOther => {
+                Optimization(OptimizationDiagnostic::unpack(OptimizationRemarkOther, di))
+            }
+            Dk::OptimizationRemarkMissed => {
                 Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di))
             }
 
-            super::DK_OptimizationRemarkAnalysis => {
+            Dk::OptimizationRemarkAnalysis => {
                 Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di))
             }
 
-            super::DK_OptimizationFailure => {
+
+            Dk::OptimizationRemarkAnalysisFPCommute => {
+                Optimization(OptimizationDiagnostic::unpack(
+                    OptimizationAnalysisFPCommute, di))
+            }
+
+            Dk::OptimizationRemarkAnalysisAliasing => {
+                Optimization(OptimizationDiagnostic::unpack(
+                    OptimizationAnalysisAliasing, di))
+            }
+
+
+            Dk::OptimizationFailure => {
                 Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di))
             }
 
diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs
index 4019732221f..622e7923d8f 100644
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
@@ -38,8 +38,6 @@ pub use self::IntPredicate::*;
 pub use self::RealPredicate::*;
 pub use self::TypeKind::*;
 pub use self::AtomicBinOp::*;
-pub use self::AtomicOrdering::*;
-pub use self::SynchronizationScope::*;
 pub use self::MetadataType::*;
 pub use self::AsmDialect::*;
 pub use self::CodeGenOptSize::*;
@@ -48,7 +46,6 @@ pub use self::CallConv::*;
 pub use self::Visibility::*;
 pub use self::DiagnosticSeverity::*;
 pub use self::Linkage::*;
-pub use self::DLLStorageClassTypes::*;
 
 use std::str::FromStr;
 use std::ffi::{CString, CStr};
@@ -132,19 +129,20 @@ pub enum Linkage {
 #[repr(C)]
 #[derive(Copy, Clone, Debug)]
 pub enum DiagnosticSeverity {
-    Error,
-    Warning,
-    Remark,
-    Note,
+    Error = 0,
+    Warning = 1,
+    Remark = 2,
+    Note = 3,
 }
 
 
 #[repr(C)]
 #[derive(Copy, Clone)]
 pub enum DLLStorageClassTypes {
-    DefaultStorageClass = 0,
-    DLLImportStorageClass = 1,
-    DLLExportStorageClass = 2,
+    Other,
+    Default,
+    DllImport,
+    DllExport,
 }
 
 bitflags! {
@@ -231,10 +229,10 @@ impl Attributes {
 
     pub fn apply_llfn(&self, idx: usize, llfn: ValueRef) {
         unsafe {
-            LLVMAddFunctionAttribute(llfn, idx as c_uint, self.regular.bits());
+            LLVMRustAddFunctionAttribute(llfn, idx as c_uint, self.regular.bits());
             if self.dereferenceable_bytes != 0 {
-                LLVMAddDereferenceableAttr(llfn, idx as c_uint,
-                                           self.dereferenceable_bytes);
+                LLVMRustAddDereferenceableAttr(llfn, idx as c_uint,
+                                               self.dereferenceable_bytes);
             }
         }
     }
@@ -243,8 +241,8 @@ impl Attributes {
         unsafe {
             LLVMRustAddCallSiteAttribute(callsite, idx as c_uint, self.regular.bits());
             if self.dereferenceable_bytes != 0 {
-                LLVMAddDereferenceableCallSiteAttr(callsite, idx as c_uint,
-                                                   self.dereferenceable_bytes);
+                LLVMRustAddDereferenceableCallSiteAttr(callsite, idx as c_uint,
+                                                       self.dereferenceable_bytes);
             }
         }
     }
@@ -348,8 +346,9 @@ pub enum AtomicOrdering {
 #[repr(C)]
 #[derive(Copy, Clone)]
 pub enum SynchronizationScope {
-    SingleThread = 0,
-    CrossThread = 1
+    Other,
+    SingleThread,
+    CrossThread,
 }
 
 #[repr(C)]
@@ -425,14 +424,18 @@ pub enum CodeModel {
 #[repr(C)]
 #[derive(Copy, Clone)]
 pub enum DiagnosticKind {
-    DK_InlineAsm = 0,
-    DK_StackSize,
-    DK_DebugMetadataVersion,
-    DK_SampleProfile,
-    DK_OptimizationRemark,
-    DK_OptimizationRemarkMissed,
-    DK_OptimizationRemarkAnalysis,
-    DK_OptimizationFailure,
+    Other,
+    InlineAsm,
+    StackSize,
+    DebugMetadataVersion,
+    SampleProfile,
+    OptimizationRemark,
+    OptimizationRemarkMissed,
+    OptimizationRemarkAnalysis,
+    OptimizationRemarkAnalysisFPCommute,
+    OptimizationRemarkAnalysisAliasing,
+    OptimizationRemarkOther,
+    OptimizationFailure,
 }
 
 #[repr(C)]
@@ -705,7 +708,7 @@ extern {
     /* Operations on other types */
     pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
     pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
-    pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
+    pub fn LLVMRustMetadataTypeInContext(C: ContextRef) -> TypeRef;
 
     /* Operations on all values */
     pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
@@ -957,8 +960,13 @@ extern {
                                        Name: *const c_char,
                                        AddressSpace: c_uint)
                                        -> ValueRef;
-    pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
-    pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
+    pub fn LLVMGetNamedGlobal(M: ModuleRef,
+                              Name: *const c_char)
+                              -> ValueRef;
+    pub fn LLVMRustGetOrInsertGlobal(M: ModuleRef,
+                                     Name: *const c_char,
+                                     T: TypeRef)
+                                     -> ValueRef;
     pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
     pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
     pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
@@ -971,7 +979,7 @@ extern {
     pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
     pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
     pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
-    pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
+    pub fn LLVMRustGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
 
     /* Operations on aliases */
     pub fn LLVMAddAlias(M: ModuleRef,
@@ -991,23 +999,27 @@ extern {
     pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
     pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
     pub fn LLVMDeleteFunction(Fn: ValueRef);
-    pub fn LLVMGetOrInsertFunction(M: ModuleRef,
-                                   Name: *const c_char,
-                                   FunctionTy: TypeRef)
-                                   -> ValueRef;
+    pub fn LLVMRustGetOrInsertFunction(M: ModuleRef,
+                                       Name: *const c_char,
+                                       FunctionTy: TypeRef)
+                                       -> ValueRef;
     pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
     pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
     pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
     pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
     pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
-    pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
-    pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
-    pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
-    pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
-                                          Name: *const c_char,
-                                          Value: *const c_char);
-    pub fn LLVMRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: uint64_t);
-    pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
+    pub fn LLVMRustAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
+    pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
+    pub fn LLVMRustAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
+    pub fn LLVMRustAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
+                                              Name: *const c_char,
+                                              Value: *const c_char);
+    pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef,
+                                            index: c_uint,
+                                            attr: uint64_t);
+    pub fn LLVMRustRemoveFunctionAttrString(Fn: ValueRef,
+                                            index: c_uint,
+                                            Name: *const c_char);
     pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_uint;
     pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_uint);
 
@@ -1077,9 +1089,9 @@ extern {
     pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef,
                                     index: c_uint,
                                     Val: uint64_t);
-    pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
-                                              index: c_uint,
-                                              bytes: uint64_t);
+    pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: ValueRef,
+                                                  index: c_uint,
+                                                  bytes: uint64_t);
 
     /* Operations on call instructions (only) */
     pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
@@ -1556,28 +1568,29 @@ extern {
                             -> ValueRef;
 
     /* Atomic Operations */
-    pub fn LLVMBuildAtomicLoad(B: BuilderRef,
-                               PointerVal: ValueRef,
-                               Name: *const c_char,
-                               Order: AtomicOrdering,
-                               Alignment: c_uint)
-                               -> ValueRef;
+    pub fn LLVMRustBuildAtomicLoad(B: BuilderRef,
+                                   PointerVal: ValueRef,
+                                   Name: *const c_char,
+                                   Order: AtomicOrdering,
+                                   Alignment: c_uint)
+                                   -> ValueRef;
 
-    pub fn LLVMBuildAtomicStore(B: BuilderRef,
-                                Val: ValueRef,
-                                Ptr: ValueRef,
-                                Order: AtomicOrdering,
-                                Alignment: c_uint)
-                                -> ValueRef;
+    pub fn LLVMRustBuildAtomicStore(B: BuilderRef,
+                                    Val: ValueRef,
+                                    Ptr: ValueRef,
+                                    Order: AtomicOrdering,
+                                    Alignment: c_uint)
+                                    -> ValueRef;
 
     pub fn LLVMRustBuildAtomicCmpXchg(B: BuilderRef,
-                                  LHS: ValueRef,
-                                  CMP: ValueRef,
-                                  RHS: ValueRef,
-                                  Order: AtomicOrdering,
-                                  FailureOrder: AtomicOrdering,
-                                  Weak: Bool)
-                                  -> ValueRef;
+                                      LHS: ValueRef,
+                                      CMP: ValueRef,
+                                      RHS: ValueRef,
+                                      Order: AtomicOrdering,
+                                      FailureOrder: AtomicOrdering,
+                                      Weak: Bool)
+                                      -> ValueRef;
+
     pub fn LLVMBuildAtomicRMW(B: BuilderRef,
                               Op: AtomicBinOp,
                               LHS: ValueRef,
@@ -1586,9 +1599,9 @@ extern {
                               SingleThreaded: Bool)
                               -> ValueRef;
 
-    pub fn LLVMBuildAtomicFence(B: BuilderRef,
-                                Order: AtomicOrdering,
-                                Scope: SynchronizationScope);
+    pub fn LLVMRustBuildAtomicFence(B: BuilderRef,
+                                    Order: AtomicOrdering,
+                                    Scope: SynchronizationScope);
 
 
     /* Selected entries from the downcasts. */
@@ -1791,248 +1804,248 @@ extern {
                                 -> ValueRef;
 
     /// Enables LLVM debug output.
-    pub fn LLVMSetDebug(Enabled: c_int);
+    pub fn LLVMRustSetDebug(Enabled: c_int);
 
     /// Prepares inline assembly.
-    pub fn LLVMInlineAsm(Ty: TypeRef,
-                         AsmString: *const c_char,
-                         Constraints: *const c_char,
-                         SideEffects: Bool,
-                         AlignStack: Bool,
-                         Dialect: c_uint)
-                         -> ValueRef;
+    pub fn LLVMRustInlineAsm(Ty: TypeRef,
+                             AsmString: *const c_char,
+                             Constraints: *const c_char,
+                             SideEffects: Bool,
+                             AlignStack: Bool,
+                             Dialect: c_uint)
+                             -> ValueRef;
 
     pub fn LLVMRustDebugMetadataVersion() -> u32;
-    pub fn LLVMVersionMajor() -> u32;
-    pub fn LLVMVersionMinor() -> u32;
+    pub fn LLVMRustVersionMajor() -> u32;
+    pub fn LLVMRustVersionMinor() -> u32;
 
     pub fn LLVMRustAddModuleFlag(M: ModuleRef,
                                  name: *const c_char,
                                  value: u32);
 
-    pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
-
-    pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
-
-    pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
-
-    pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
-                                          Lang: c_uint,
-                                          File: *const c_char,
-                                          Dir: *const c_char,
-                                          Producer: *const c_char,
-                                          isOptimized: bool,
-                                          Flags: *const c_char,
-                                          RuntimeVer: c_uint,
-                                          SplitName: *const c_char)
-                                          -> DIDescriptor;
-
-    pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
-                                   Filename: *const c_char,
-                                   Directory: *const c_char)
-                                   -> DIFile;
-
-    pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
-                                             File: DIFile,
-                                             ParameterTypes: DIArray)
-                                             -> DICompositeType;
+    pub fn LLVMRustDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
+
+    pub fn LLVMRustDIBuilderDispose(Builder: DIBuilderRef);
+
+    pub fn LLVMRustDIBuilderFinalize(Builder: DIBuilderRef);
+
+    pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
+                                              Lang: c_uint,
+                                              File: *const c_char,
+                                              Dir: *const c_char,
+                                              Producer: *const c_char,
+                                              isOptimized: bool,
+                                              Flags: *const c_char,
+                                              RuntimeVer: c_uint,
+                                              SplitName: *const c_char)
+                                              -> DIDescriptor;
+
+    pub fn LLVMRustDIBuilderCreateFile(Builder: DIBuilderRef,
+                                       Filename: *const c_char,
+                                       Directory: *const c_char)
+                                       -> DIFile;
+
+    pub fn LLVMRustDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
+                                                 File: DIFile,
+                                                 ParameterTypes: DIArray)
+                                                 -> DICompositeType;
+
+    pub fn LLVMRustDIBuilderCreateFunction(Builder: DIBuilderRef,
+                                           Scope: DIDescriptor,
+                                           Name: *const c_char,
+                                           LinkageName: *const c_char,
+                                           File: DIFile,
+                                           LineNo: c_uint,
+                                           Ty: DIType,
+                                           isLocalToUnit: bool,
+                                           isDefinition: bool,
+                                           ScopeLine: c_uint,
+                                           Flags: c_uint,
+                                           isOptimized: bool,
+                                           Fn: ValueRef,
+                                           TParam: DIArray,
+                                           Decl: DIDescriptor)
+                                           -> DISubprogram;
+
+    pub fn LLVMRustDIBuilderCreateBasicType(Builder: DIBuilderRef,
+                                            Name: *const c_char,
+                                            SizeInBits: u64,
+                                            AlignInBits: u64,
+                                            Encoding: c_uint)
+                                            -> DIBasicType;
 
-    pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
-                                       Scope: DIDescriptor,
-                                       Name: *const c_char,
-                                       LinkageName: *const c_char,
-                                       File: DIFile,
-                                       LineNo: c_uint,
-                                       Ty: DIType,
-                                       isLocalToUnit: bool,
-                                       isDefinition: bool,
-                                       ScopeLine: c_uint,
-                                       Flags: c_uint,
-                                       isOptimized: bool,
-                                       Fn: ValueRef,
-                                       TParam: DIArray,
-                                       Decl: DIDescriptor)
-                                       -> DISubprogram;
-
-    pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
-                                        Name: *const c_char,
-                                        SizeInBits: c_ulonglong,
-                                        AlignInBits: c_ulonglong,
-                                        Encoding: c_uint)
-                                        -> DIBasicType;
-
-    pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
+    pub fn LLVMRustDIBuilderCreatePointerType(Builder: DIBuilderRef,
                                           PointeeTy: DIType,
-                                          SizeInBits: c_ulonglong,
-                                          AlignInBits: c_ulonglong,
+                                          SizeInBits: u64,
+                                          AlignInBits: u64,
                                           Name: *const c_char)
                                           -> DIDerivedType;
 
-    pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
-                                         Scope: DIDescriptor,
-                                         Name: *const c_char,
-                                         File: DIFile,
-                                         LineNumber: c_uint,
-                                         SizeInBits: c_ulonglong,
-                                         AlignInBits: c_ulonglong,
-                                         Flags: c_uint,
-                                         DerivedFrom: DIType,
-                                         Elements: DIArray,
-                                         RunTimeLang: c_uint,
-                                         VTableHolder: DIType,
-                                         UniqueId: *const c_char)
-                                         -> DICompositeType;
-
-    pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
-                                         Scope: DIDescriptor,
-                                         Name: *const c_char,
-                                         File: DIFile,
-                                         LineNo: c_uint,
-                                         SizeInBits: c_ulonglong,
-                                         AlignInBits: c_ulonglong,
-                                         OffsetInBits: c_ulonglong,
-                                         Flags: c_uint,
-                                         Ty: DIType)
-                                         -> DIDerivedType;
-
-    pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
-                                           Scope: DIScope,
-                                           File: DIFile,
-                                           Line: c_uint,
-                                           Col: c_uint)
-                                           -> DILexicalBlock;
+    pub fn LLVMRustDIBuilderCreateStructType(Builder: DIBuilderRef,
+                                             Scope: DIDescriptor,
+                                             Name: *const c_char,
+                                             File: DIFile,
+                                             LineNumber: c_uint,
+                                             SizeInBits: u64,
+                                             AlignInBits: u64,
+                                             Flags: c_uint,
+                                             DerivedFrom: DIType,
+                                             Elements: DIArray,
+                                             RunTimeLang: c_uint,
+                                             VTableHolder: DIType,
+                                             UniqueId: *const c_char)
+                                             -> DICompositeType;
 
-    pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
-                                             Context: DIScope,
+    pub fn LLVMRustDIBuilderCreateMemberType(Builder: DIBuilderRef,
+                                             Scope: DIDescriptor,
                                              Name: *const c_char,
-                                             LinkageName: *const c_char,
                                              File: DIFile,
                                              LineNo: c_uint,
+                                             SizeInBits: u64,
+                                             AlignInBits: u64,
+                                             OffsetInBits: u64,
+                                             Flags: c_uint,
+                                             Ty: DIType)
+                                             -> DIDerivedType;
+
+    pub fn LLVMRustDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
+                                               Scope: DIScope,
+                                               File: DIFile,
+                                               Line: c_uint,
+                                               Col: c_uint)
+                                               -> DILexicalBlock;
+
+    pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
+                                                 Context: DIScope,
+                                                 Name: *const c_char,
+                                                 LinkageName: *const c_char,
+                                                 File: DIFile,
+                                                 LineNo: c_uint,
+                                                 Ty: DIType,
+                                                 isLocalToUnit: bool,
+                                                 Val: ValueRef,
+                                                 Decl: DIDescriptor)
+                                                 -> DIGlobalVariable;
+
+    pub fn LLVMRustDIBuilderCreateVariable(Builder: DIBuilderRef,
+                                           Tag: c_uint,
+                                           Scope: DIDescriptor,
+                                           Name: *const c_char,
+                                           File: DIFile,
+                                           LineNo: c_uint,
+                                           Ty: DIType,
+                                           AlwaysPreserve: bool,
+                                           Flags: c_uint,
+                                           AddrOps: *const i64,
+                                           AddrOpsCount: c_uint,
+                                           ArgNo: c_uint)
+                                           -> DIVariable;
+
+    pub fn LLVMRustDIBuilderCreateArrayType(Builder: DIBuilderRef,
+                                            Size: u64,
+                                            AlignInBits: u64,
+                                            Ty: DIType,
+                                            Subscripts: DIArray)
+                                            -> DIType;
+
+    pub fn LLVMRustDIBuilderCreateVectorType(Builder: DIBuilderRef,
+                                             Size: u64,
+                                             AlignInBits: u64,
                                              Ty: DIType,
-                                             isLocalToUnit: bool,
-                                             Val: ValueRef,
-                                             Decl: DIDescriptor)
-                                             -> DIGlobalVariable;
-
-    pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
-                                            Tag: c_uint,
-                                            Scope: DIDescriptor,
+                                             Subscripts: DIArray)
+                                             -> DIType;
+
+    pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
+                                                Lo: i64,
+                                                Count: i64)
+                                                -> DISubrange;
+
+    pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
+                                             Ptr: *const DIDescriptor,
+                                             Count: c_uint)
+                                             -> DIArray;
+
+    pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
+                                               Val: ValueRef,
+                                               VarInfo: DIVariable,
+                                               AddrOps: *const i64,
+                                               AddrOpsCount: c_uint,
+                                               DL: ValueRef,
+                                               InsertAtEnd: BasicBlockRef)
+                                               -> ValueRef;
+
+    pub fn LLVMRustDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
+                                                Val: ValueRef,
+                                                VarInfo: DIVariable,
+                                                AddrOps: *const i64,
+                                                AddrOpsCount: c_uint,
+                                                DL: ValueRef,
+                                                InsertBefore: ValueRef)
+                                                -> ValueRef;
+
+    pub fn LLVMRustDIBuilderCreateEnumerator(Builder: DIBuilderRef,
+                                             Name: *const c_char,
+                                             Val: u64)
+                                             -> DIEnumerator;
+
+    pub fn LLVMRustDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
+                                                  Scope: DIScope,
+                                                  Name: *const c_char,
+                                                  File: DIFile,
+                                                  LineNumber: c_uint,
+                                                  SizeInBits: u64,
+                                                  AlignInBits: u64,
+                                                  Elements: DIArray,
+                                                  ClassType: DIType)
+                                                  -> DIType;
+
+    pub fn LLVMRustDIBuilderCreateUnionType(Builder: DIBuilderRef,
+                                            Scope: DIScope,
                                             Name: *const c_char,
                                             File: DIFile,
-                                            LineNo: c_uint,
-                                            Ty: DIType,
-                                            AlwaysPreserve: bool,
+                                            LineNumber: c_uint,
+                                            SizeInBits: u64,
+                                            AlignInBits: u64,
                                             Flags: c_uint,
-                                            AddrOps: *const i64,
-                                            AddrOpsCount: c_uint,
-                                            ArgNo: c_uint)
-                                            -> DIVariable;
-
-    pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
-                                        Size: c_ulonglong,
-                                        AlignInBits: c_ulonglong,
-                                        Ty: DIType,
-                                        Subscripts: DIArray)
-                                        -> DIType;
-
-    pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
-                                         Size: c_ulonglong,
-                                         AlignInBits: c_ulonglong,
-                                         Ty: DIType,
-                                         Subscripts: DIArray)
-                                         -> DIType;
-
-    pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
-                                            Lo: c_longlong,
-                                            Count: c_longlong)
-                                            -> DISubrange;
-
-    pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
-                                         Ptr: *const DIDescriptor,
-                                         Count: c_uint)
-                                         -> DIArray;
-
-    pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
-                                           Val: ValueRef,
-                                           VarInfo: DIVariable,
-                                           AddrOps: *const i64,
-                                           AddrOpsCount: c_uint,
-                                           DL: ValueRef,
-                                           InsertAtEnd: BasicBlockRef)
-                                           -> ValueRef;
-
-    pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
-                                            Val: ValueRef,
-                                            VarInfo: DIVariable,
-                                            AddrOps: *const i64,
-                                            AddrOpsCount: c_uint,
-                                            DL: ValueRef,
-                                            InsertBefore: ValueRef)
-                                            -> ValueRef;
-
-    pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
-                                         Name: *const c_char,
-                                         Val: c_ulonglong)
-                                         -> DIEnumerator;
-
-    pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
-                                              Scope: DIScope,
-                                              Name: *const c_char,
-                                              File: DIFile,
-                                              LineNumber: c_uint,
-                                              SizeInBits: c_ulonglong,
-                                              AlignInBits: c_ulonglong,
-                                              Elements: DIArray,
-                                              ClassType: DIType)
-                                              -> DIType;
-
-    pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
-                                        Scope: DIScope,
-                                        Name: *const c_char,
-                                        File: DIFile,
-                                        LineNumber: c_uint,
-                                        SizeInBits: c_ulonglong,
-                                        AlignInBits: c_ulonglong,
-                                        Flags: c_uint,
-                                        Elements: DIArray,
-                                        RunTimeLang: c_uint,
-                                        UniqueId: *const c_char)
-                                        -> DIType;
+                                            Elements: DIArray,
+                                            RunTimeLang: c_uint,
+                                            UniqueId: *const c_char)
+                                            -> DIType;
 
     pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
 
-    pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
-                                                    Scope: DIScope,
-                                                    Name: *const c_char,
-                                                    Ty: DIType,
-                                                    File: DIFile,
-                                                    LineNo: c_uint,
-                                                    ColumnNo: c_uint)
-                                                    -> DITemplateTypeParameter;
-
-    pub fn LLVMDIBuilderCreateOpDeref() -> i64;
-
-    pub fn LLVMDIBuilderCreateOpPlus() -> i64;
-
-    pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
-                                        Scope: DIScope,
-                                        Name: *const c_char,
-                                        File: DIFile,
-                                        LineNo: c_uint)
-                                        -> DINameSpace;
-
-    pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
-                                            Line: c_uint,
-                                            Column: c_uint,
+    pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
+                                                        Scope: DIScope,
+                                                        Name: *const c_char,
+                                                        Ty: DIType,
+                                                        File: DIFile,
+                                                        LineNo: c_uint,
+                                                        ColumnNo: c_uint)
+                                                        -> DITemplateTypeParameter;
+
+
+    pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef,
                                             Scope: DIScope,
-                                            InlinedAt: MetadataRef)
-                                            -> ValueRef;
+                                            Name: *const c_char,
+                                            File: DIFile,
+                                            LineNo: c_uint)
+                                            -> DINameSpace;
+    pub fn LLVMRustDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
+                                               CompositeType: DIType,
+                                               TypeArray: DIArray);
+
+
+    pub fn LLVMRustDIBuilderCreateDebugLocation(Context: ContextRef,
+                                                Line: c_uint,
+                                                Column: c_uint,
+                                                Scope: DIScope,
+                                                InlinedAt: MetadataRef)
+                                                -> ValueRef;
+    pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
+    pub fn LLVMRustDIBuilderCreateOpPlus() -> i64;
 
-    pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
-                                           CompositeType: DIType,
-                                           TypeArray: DIArray);
-    pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
-    pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
+    pub fn LLVMRustWriteTypeToString(Type: TypeRef, s: RustStringRef);
+    pub fn LLVMRustWriteValueToString(value_ref: ValueRef, s: RustStringRef);
 
     pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
 
@@ -2108,35 +2121,38 @@ extern {
                                       C: DLLStorageClassTypes);
 
     pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
-                                  data: *mut *const c_char) -> c_int;
+                                  data: *mut *const c_char) -> size_t;
 
-    pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
+    pub fn LLVMRustWriteTwineToString(T: TwineRef, s: RustStringRef);
 
     pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
                                            Handler: DiagnosticHandler,
                                            DiagnosticContext: *mut c_void);
 
-    pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
-                                            pass_name_out: *mut *const c_char,
-                                            function_out: *mut ValueRef,
-                                            debugloc_out: *mut DebugLocRef,
-                                            message_out: *mut TwineRef);
-    pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
-                                            cookie_out: *mut c_uint,
-                                            message_out: *mut TwineRef,
-                                            instruction_out: *mut ValueRef);
-
-    pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
+    pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
+                                                pass_name_out: *mut *const c_char,
+                                                function_out: *mut ValueRef,
+                                                debugloc_out: *mut DebugLocRef,
+                                                message_out: *mut TwineRef);
+    pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
+                                             cookie_out: *mut c_uint,
+                                             message_out: *mut TwineRef,
+                                             instruction_out: *mut ValueRef);
+
+    pub fn LLVMRustWriteDiagnosticInfoToString(DI: DiagnosticInfoRef,
+                                               s: RustStringRef);
     pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
-    pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
+    pub fn LLVMRustGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
 
-    pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
+    pub fn LLVMRustWriteDebugLocToString(C: ContextRef,
+                                         DL: DebugLocRef,
+                                         s: RustStringRef);
 
-    pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
-                                             H: InlineAsmDiagHandler,
-                                             CX: *mut c_void);
+    pub fn LLVMRustSetInlineAsmDiagnosticHandler(C: ContextRef,
+                                                 H: InlineAsmDiagHandler,
+                                                 CX: *mut c_void);
 
-    pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
+    pub fn LLVMRustWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
 
     pub fn LLVMRustWriteArchive(Dst: *const c_char,
                                 NumMembers: size_t,
@@ -2237,15 +2253,15 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
 
 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
     unsafe {
-        LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
-                                 attr.bits() as uint64_t)
+        LLVMRustAddFunctionAttribute(fn_, FunctionIndex as c_uint,
+                                     attr.bits() as uint64_t)
     }
 }
 
 pub fn RemoveFunctionAttributes(fn_: ValueRef, attr: Attribute) {
     unsafe {
-        LLVMRemoveFunctionAttributes(fn_, FunctionIndex as c_uint,
-                                           attr.bits() as uint64_t)
+        LLVMRustRemoveFunctionAttributes(fn_, FunctionIndex as c_uint,
+                                         attr.bits() as uint64_t)
     }
 }
 
@@ -2366,12 +2382,12 @@ pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
 }
 
 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
-    build_string(|s| LLVMWriteTwineToString(tr, s))
+    build_string(|s| LLVMRustWriteTwineToString(tr, s))
         .expect("got a non-UTF8 Twine from LLVM")
 }
 
 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
-    build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
+    build_string(|s| LLVMRustWriteDebugLocToString(c, tr, s))
         .expect("got a non-UTF8 DebugLoc from LLVM")
 }
 
diff --git a/src/librustc_trans/attributes.rs b/src/librustc_trans/attributes.rs
index 01e9970dc76..9c121ae9bfc 100644
--- a/src/librustc_trans/attributes.rs
+++ b/src/librustc_trans/attributes.rs
@@ -80,10 +80,10 @@ pub fn set_frame_pointer_elimination(ccx: &CrateContext, llfn: ValueRef) {
         unsafe {
             let attr = "no-frame-pointer-elim\0".as_ptr() as *const _;
             let val = "true\0".as_ptr() as *const _;
-            llvm::LLVMAddFunctionAttrStringValue(llfn,
-                                                 llvm::FunctionIndex as c_uint,
-                                                 attr,
-                                                 val);
+            llvm::LLVMRustAddFunctionAttrStringValue(llfn,
+                                                     llvm::FunctionIndex as c_uint,
+                                                     attr,
+                                                     val);
         }
     }
 }
diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs
index 0f3a45a7cff..8ce2fa762f9 100644
--- a/src/librustc_trans/back/write.rs
+++ b/src/librustc_trans/back/write.rs
@@ -365,7 +365,7 @@ unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
                                         cookie: c_uint) {
     let HandlerFreeVars { cgcx, .. } = *(user as *const HandlerFreeVars);
 
-    let msg = llvm::build_string(|s| llvm::LLVMWriteSMDiagnosticToString(diag, s))
+    let msg = llvm::build_string(|s| llvm::LLVMRustWriteSMDiagnosticToString(diag, s))
         .expect("non-UTF8 SMDiagnostic");
 
     report_inline_asm(cgcx, &msg[..], cookie);
@@ -421,7 +421,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
     };
     let fv = &fv as *const HandlerFreeVars as *mut c_void;
 
-    llvm::LLVMSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, fv);
+    llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, fv);
     llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, fv);
 
     let module_name = Some(&mtrans.name[..]);
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index 5a19ddff746..3e66f6de242 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -2348,7 +2348,8 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
 
                     if !is_referenced_somewhere && !is_reachable && !has_fixed_linkage {
                         llvm::SetLinkage(val, llvm::InternalLinkage);
-                        llvm::SetDLLStorageClass(val, llvm::DefaultStorageClass);
+                        llvm::SetDLLStorageClass(val,
+                                                 llvm::DLLStorageClassTypes::Default);
                         llvm::UnsetComdat(val);
                     }
                 }
diff --git a/src/librustc_trans/builder.rs b/src/librustc_trans/builder.rs
index 7495f2b753b..12809ab2684 100644
--- a/src/librustc_trans/builder.rs
+++ b/src/librustc_trans/builder.rs
@@ -503,8 +503,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         unsafe {
             let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
             let align = llalign_of_pref(self.ccx, ty.element_type());
-            llvm::LLVMBuildAtomicLoad(self.llbuilder, ptr, noname(), order,
-                                      align as c_uint)
+            llvm::LLVMRustBuildAtomicLoad(self.llbuilder, ptr, noname(), order,
+                                          align as c_uint)
         }
     }
 
@@ -565,7 +565,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         unsafe {
             let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
             let align = llalign_of_pref(self.ccx, ty.element_type());
-            llvm::LLVMBuildAtomicStore(self.llbuilder, val, ptr, order, align as c_uint);
+            llvm::LLVMRustBuildAtomicStore(self.llbuilder, val, ptr, order, align as c_uint);
         }
     }
 
@@ -840,7 +840,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         debug!("Asm Output Type: {:?}", output);
         let fty = Type::func(&argtys[..], &output);
         unsafe {
-            let v = llvm::LLVMInlineAsm(
+            let v = llvm::LLVMRustInlineAsm(
                 fty.to_ref(), asm, cons, volatile, alignstack, dia as c_uint);
             self.call(v, inputs, None)
         }
@@ -1097,7 +1097,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
 
     pub fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope) {
         unsafe {
-            llvm::LLVMBuildAtomicFence(self.llbuilder, order, scope);
+            llvm::LLVMRustBuildAtomicFence(self.llbuilder, order, scope);
         }
     }
 }
diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs
index 27048994254..996efc9c113 100644
--- a/src/librustc_trans/consts.rs
+++ b/src/librustc_trans/consts.rs
@@ -1126,7 +1126,7 @@ pub fn get_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, def_id: DefId)
             }
         }
         if ccx.use_dll_storage_attrs() {
-            llvm::SetDLLStorageClass(g, llvm::DLLImportStorageClass);
+            llvm::SetDLLStorageClass(g, llvm::DLLStorageClassTypes::DllImport);
         }
         g
     };
@@ -1182,7 +1182,7 @@ pub fn trans_static(ccx: &CrateContext,
             let name_str_ref = CStr::from_ptr(llvm::LLVMGetValueName(datum.val));
             let name_string = CString::new(name_str_ref.to_bytes()).unwrap();
             llvm::LLVMSetValueName(datum.val, empty_string.as_ptr());
-            let new_g = llvm::LLVMGetOrInsertGlobal(
+            let new_g = llvm::LLVMRustGetOrInsertGlobal(
                 ccx.llmod(), name_string.as_ptr(), val_llty.to_ref());
             // To avoid breaking any invariants, we leave around the old
             // global for the moment; we'll replace all references to it
diff --git a/src/librustc_trans/debuginfo/create_scope_map.rs b/src/librustc_trans/debuginfo/create_scope_map.rs
index 0b754024868..fe6a48d4c55 100644
--- a/src/librustc_trans/debuginfo/create_scope_map.rs
+++ b/src/librustc_trans/debuginfo/create_scope_map.rs
@@ -133,7 +133,7 @@ fn make_mir_scope(ccx: &CrateContext,
     let loc = span_start(ccx, scope_data.span);
     scopes[scope] = unsafe {
     let file_metadata = file_metadata(ccx, &loc.file.name, &loc.file.abs_path);
-        llvm::LLVMDIBuilderCreateLexicalBlock(
+        llvm::LLVMRustDIBuilderCreateLexicalBlock(
             DIB(ccx),
             parent_scope,
             file_metadata,
@@ -156,7 +156,7 @@ fn with_new_scope<F>(cx: &CrateContext,
     let parent_scope = scope_stack.last().unwrap().scope_metadata;
 
     let scope_metadata = unsafe {
-        llvm::LLVMDIBuilderCreateLexicalBlock(
+        llvm::LLVMRustDIBuilderCreateLexicalBlock(
             DIB(cx),
             parent_scope,
             file_metadata,
@@ -272,7 +272,7 @@ fn walk_pattern(cx: &CrateContext,
                 let parent_scope = scope_stack.last().unwrap().scope_metadata;
 
                 let scope_metadata = unsafe {
-                    llvm::LLVMDIBuilderCreateLexicalBlock(
+                    llvm::LLVMRustDIBuilderCreateLexicalBlock(
                         DIB(cx),
                         parent_scope,
                         file_metadata,
diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs
index 1d718d4b57a..8011347d3eb 100644
--- a/src/librustc_trans/debuginfo/metadata.rs
+++ b/src/librustc_trans/debuginfo/metadata.rs
@@ -504,12 +504,12 @@ fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     };
 
     let subrange = unsafe {
-        llvm::LLVMDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)
+        llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)
     };
 
     let subscripts = create_DIArray(DIB(cx), &[subrange]);
     let metadata = unsafe {
-        llvm::LLVMDIBuilderCreateArrayType(
+        llvm::LLVMRustDIBuilderCreateArrayType(
             DIB(cx),
             bytes_to_bits(array_size_in_bytes),
             bytes_to_bits(element_type_align),
@@ -612,7 +612,7 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
     return MetadataCreationResult::new(
         unsafe {
-            llvm::LLVMDIBuilderCreateSubroutineType(
+            llvm::LLVMRustDIBuilderCreateSubroutineType(
                 DIB(cx),
                 unknown_file_metadata(cx),
                 create_DIArray(DIB(cx), &signature_metadata[..]))
@@ -885,8 +885,8 @@ fn file_metadata_(cx: &CrateContext, key: &str, file_name: &str, work_dir: &str)
     let file_name = CString::new(file_name).unwrap();
     let work_dir = CString::new(work_dir).unwrap();
     let file_metadata = unsafe {
-        llvm::LLVMDIBuilderCreateFile(DIB(cx), file_name.as_ptr(),
-                                      work_dir.as_ptr())
+        llvm::LLVMRustDIBuilderCreateFile(DIB(cx), file_name.as_ptr(),
+                                          work_dir.as_ptr())
     };
 
     let mut created_files = debug_context(cx).created_files.borrow_mut();
@@ -916,7 +916,7 @@ pub fn scope_metadata(fcx: &FunctionContext,
 
 pub fn diverging_type_metadata(cx: &CrateContext) -> DIType {
     unsafe {
-        llvm::LLVMDIBuilderCreateBasicType(
+        llvm::LLVMRustDIBuilderCreateBasicType(
             DIB(cx),
             "!\0".as_ptr() as *const _,
             bytes_to_bits(0),
@@ -951,7 +951,7 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     let (size, align) = size_and_align_of(cx, llvm_type);
     let name = CString::new(name).unwrap();
     let ty_metadata = unsafe {
-        llvm::LLVMDIBuilderCreateBasicType(
+        llvm::LLVMRustDIBuilderCreateBasicType(
             DIB(cx),
             name.as_ptr(),
             bytes_to_bits(size),
@@ -971,7 +971,7 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     let name = compute_debuginfo_type_name(cx, pointer_type, false);
     let name = CString::new(name).unwrap();
     let ptr_metadata = unsafe {
-        llvm::LLVMDIBuilderCreatePointerType(
+        llvm::LLVMRustDIBuilderCreatePointerType(
             DIB(cx),
             pointee_type_metadata,
             bytes_to_bits(pointer_size),
@@ -1017,7 +1017,7 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
     let flags = "\0";
     let split_name = "\0";
     return unsafe {
-        llvm::LLVMDIBuilderCreateCompileUnit(
+        llvm::LLVMRustDIBuilderCreateCompileUnit(
             debug_context.builder,
             DW_LANG_RUST,
             compile_unit_name,
@@ -1596,7 +1596,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
             let token = v.name.as_str();
             let name = CString::new(token.as_bytes()).unwrap();
             unsafe {
-                llvm::LLVMDIBuilderCreateEnumerator(
+                llvm::LLVMRustDIBuilderCreateEnumerator(
                     DIB(cx),
                     name.as_ptr(),
                     v.disr_val.to_u64_unchecked())
@@ -1623,7 +1623,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
                 let name = CString::new(discriminant_name.as_bytes()).unwrap();
                 let discriminant_type_metadata = unsafe {
-                    llvm::LLVMDIBuilderCreateEnumerationType(
+                    llvm::LLVMRustDIBuilderCreateEnumerationType(
                         DIB(cx),
                         containing_scope,
                         name.as_ptr(),
@@ -1667,7 +1667,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     let enum_name = CString::new(enum_name).unwrap();
     let unique_type_id_str = CString::new(unique_type_id_str.as_bytes()).unwrap();
     let enum_metadata = unsafe {
-        llvm::LLVMDIBuilderCreateUnionType(
+        llvm::LLVMRustDIBuilderCreateUnionType(
         DIB(cx),
         containing_scope,
         enum_name.as_ptr(),
@@ -1769,7 +1769,7 @@ fn set_members_of_composite_type(cx: &CrateContext,
             let member_name = member_description.name.as_bytes();
             let member_name = CString::new(member_name).unwrap();
             unsafe {
-                llvm::LLVMDIBuilderCreateMemberType(
+                llvm::LLVMRustDIBuilderCreateMemberType(
                     DIB(cx),
                     composite_type_metadata,
                     member_name.as_ptr(),
@@ -1786,13 +1786,14 @@ fn set_members_of_composite_type(cx: &CrateContext,
 
     unsafe {
         let type_array = create_DIArray(DIB(cx), &member_metadata[..]);
-        llvm::LLVMDICompositeTypeSetTypeArray(DIB(cx), composite_type_metadata, type_array);
+        llvm::LLVMRustDICompositeTypeSetTypeArray(
+            DIB(cx), composite_type_metadata, type_array);
     }
 }
 
-// A convenience wrapper around LLVMDIBuilderCreateStructType(). Does not do any
-// caching, does not add any fields to the struct. This can be done later with
-// set_members_of_composite_type().
+// A convenience wrapper around LLVMRustDIBuilderCreateStructType(). Does not do
+// any caching, does not add any fields to the struct. This can be done later
+// with set_members_of_composite_type().
 fn create_struct_stub(cx: &CrateContext,
                       struct_llvm_type: Type,
                       struct_type_name: &str,
@@ -1807,12 +1808,12 @@ fn create_struct_stub(cx: &CrateContext,
     let name = CString::new(struct_type_name).unwrap();
     let unique_type_id = CString::new(unique_type_id_str.as_bytes()).unwrap();
     let metadata_stub = unsafe {
-        // LLVMDIBuilderCreateStructType() wants an empty array. A null
+        // LLVMRustDIBuilderCreateStructType() wants an empty array. A null
         // pointer will lead to hard to trace and debug LLVM assertions
         // later on in llvm/lib/IR/Value.cpp.
         let empty_array = create_DIArray(DIB(cx), &[]);
 
-        llvm::LLVMDIBuilderCreateStructType(
+        llvm::LLVMRustDIBuilderCreateStructType(
             DIB(cx),
             containing_scope,
             name.as_ptr(),
@@ -1868,16 +1869,16 @@ pub fn create_global_var_metadata(cx: &CrateContext,
     let var_name = CString::new(var_name).unwrap();
     let linkage_name = CString::new(linkage_name).unwrap();
     unsafe {
-        llvm::LLVMDIBuilderCreateStaticVariable(DIB(cx),
-                                                var_scope,
-                                                var_name.as_ptr(),
-                                                linkage_name.as_ptr(),
-                                                file_metadata,
-                                                line_number,
-                                                type_metadata,
-                                                is_local_to_unit,
-                                                global,
-                                                ptr::null_mut());
+        llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
+                                                    var_scope,
+                                                    var_name.as_ptr(),
+                                                    linkage_name.as_ptr(),
+                                                    file_metadata,
+                                                    line_number,
+                                                    type_metadata,
+                                                    is_local_to_unit,
+                                                    global,
+                                                    ptr::null_mut());
     }
 }
 
@@ -1980,10 +1981,10 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                                                               env_index);
 
     let address_operations = unsafe {
-        [llvm::LLVMDIBuilderCreateOpDeref(),
-         llvm::LLVMDIBuilderCreateOpPlus(),
+        [llvm::LLVMRustDIBuilderCreateOpDeref(),
+         llvm::LLVMRustDIBuilderCreateOpPlus(),
          byte_offset_of_var_in_env as i64,
-         llvm::LLVMDIBuilderCreateOpDeref()]
+         llvm::LLVMRustDIBuilderCreateOpDeref()]
     };
 
     let address_op_count = if captured_by_ref {
@@ -2021,7 +2022,7 @@ pub fn create_match_binding_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
 
     let scope_metadata = scope_metadata(bcx.fcx, binding.id, binding.span);
     let aops = unsafe {
-        [llvm::LLVMDIBuilderCreateOpDeref()]
+        [llvm::LLVMRustDIBuilderCreateOpDeref()]
     };
     // Regardless of the actual type (`T`) we're always passed the stack slot
     // (alloca) for the binding. For ByRef bindings that's a `T*` but for ByMove
diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs
index 0cb52c8768b..915999f07a1 100644
--- a/src/librustc_trans/debuginfo/mod.rs
+++ b/src/librustc_trans/debuginfo/mod.rs
@@ -88,7 +88,7 @@ pub struct CrateDebugContext<'tcx> {
 impl<'tcx> CrateDebugContext<'tcx> {
     pub fn new(llmod: ModuleRef) -> CrateDebugContext<'tcx> {
         debug!("CrateDebugContext::new");
-        let builder = unsafe { llvm::LLVMDIBuilderCreate(llmod) };
+        let builder = unsafe { llvm::LLVMRustDIBuilderCreate(llmod) };
         // DIBuilder inherits context from the module, so we'd better use the same one
         let llcontext = unsafe { llvm::LLVMGetModuleContext(llmod) };
         return CrateDebugContext {
@@ -178,8 +178,8 @@ pub fn finalize(cx: &CrateContext) {
     }
 
     unsafe {
-        llvm::LLVMDIBuilderFinalize(DIB(cx));
-        llvm::LLVMDIBuilderDispose(DIB(cx));
+        llvm::LLVMRustDIBuilderFinalize(DIB(cx));
+        llvm::LLVMRustDIBuilderDispose(DIB(cx));
         // Debuginfo generation in LLVM by default uses a higher
         // version of dwarf than OS X currently understands. We can
         // instruct LLVM to emit an older version of dwarf, however,
@@ -250,7 +250,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
 
     let function_type_metadata = unsafe {
         let fn_signature = get_function_signature(cx, sig, abi);
-        llvm::LLVMDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature)
+        llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature)
     };
 
     // Find the enclosing function, in case this is a closure.
@@ -284,7 +284,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     let linkage_name = CString::new(linkage_name).unwrap();
 
     let fn_metadata = unsafe {
-        llvm::LLVMDIBuilderCreateFunction(
+        llvm::LLVMRustDIBuilderCreateFunction(
             DIB(cx),
             containing_scope,
             function_name.as_ptr(),
@@ -388,7 +388,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                 let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
                 let name = CString::new(param.name.as_str().as_bytes()).unwrap();
                 unsafe {
-                    llvm::LLVMDIBuilderCreateTemplateTypeParameter(
+                    llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
                         DIB(cx),
                         ptr::null_mut(),
                         name.as_ptr(),
@@ -492,7 +492,7 @@ pub fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         (DirectVariable { alloca }, address_operations) |
         (IndirectVariable {alloca, address_operations}, _) => {
             let metadata = unsafe {
-                llvm::LLVMDIBuilderCreateVariable(
+                llvm::LLVMRustDIBuilderCreateVariable(
                     DIB(cx),
                     dwarf_tag,
                     scope_metadata,
@@ -510,7 +510,7 @@ pub fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                 InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize()));
             unsafe {
                 let debug_loc = llvm::LLVMGetCurrentDebugLocation(cx.raw_builder());
-                let instr = llvm::LLVMDIBuilderInsertDeclareAtEnd(
+                let instr = llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
                     DIB(cx),
                     alloca,
                     metadata,
diff --git a/src/librustc_trans/debuginfo/namespace.rs b/src/librustc_trans/debuginfo/namespace.rs
index 736a8c1c7d7..5953ec4aaed 100644
--- a/src/librustc_trans/debuginfo/namespace.rs
+++ b/src/librustc_trans/debuginfo/namespace.rs
@@ -78,7 +78,7 @@ pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
     };
 
     let scope = unsafe {
-        llvm::LLVMDIBuilderCreateNameSpace(
+        llvm::LLVMRustDIBuilderCreateNameSpace(
             DIB(ccx),
             parent_scope,
             namespace_name.as_ptr(),
diff --git a/src/librustc_trans/debuginfo/source_loc.rs b/src/librustc_trans/debuginfo/source_loc.rs
index 9726001b4d4..d288b9dcef7 100644
--- a/src/librustc_trans/debuginfo/source_loc.rs
+++ b/src/librustc_trans/debuginfo/source_loc.rs
@@ -206,7 +206,7 @@ pub fn set_debug_location(cx: &CrateContext,
             debug!("setting debug location to {} {}", line, col);
 
             unsafe {
-                llvm::LLVMDIBuilderCreateDebugLocation(
+                llvm::LLVMRustDIBuilderCreateDebugLocation(
                     debug_context(cx).llcontext,
                     line as c_uint,
                     col as c_uint,
diff --git a/src/librustc_trans/debuginfo/utils.rs b/src/librustc_trans/debuginfo/utils.rs
index facdfe73ddc..5734a123941 100644
--- a/src/librustc_trans/debuginfo/utils.rs
+++ b/src/librustc_trans/debuginfo/utils.rs
@@ -40,7 +40,7 @@ pub fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool
 #[allow(non_snake_case)]
 pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
     return unsafe {
-        llvm::LLVMDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
+        llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
     };
 }
 
diff --git a/src/librustc_trans/declare.rs b/src/librustc_trans/declare.rs
index 2746d3fb6b0..15d90504ee7 100644
--- a/src/librustc_trans/declare.rs
+++ b/src/librustc_trans/declare.rs
@@ -40,7 +40,7 @@ pub fn declare_global(ccx: &CrateContext, name: &str, ty: Type) -> llvm::ValueRe
         bug!("name {:?} contains an interior null byte", name)
     });
     unsafe {
-        llvm::LLVMGetOrInsertGlobal(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
+        llvm::LLVMRustGetOrInsertGlobal(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
     }
 }
 
@@ -55,7 +55,7 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
         bug!("name {:?} contains an interior null byte", name)
     });
     let llfn = unsafe {
-        llvm::LLVMGetOrInsertFunction(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
+        llvm::LLVMRustGetOrInsertFunction(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
     };
 
     llvm::SetFunctionCallConv(llfn, callconv);
@@ -173,7 +173,7 @@ pub fn get_declared_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
     let namebuf = CString::new(name).unwrap_or_else(|_|{
         bug!("name {:?} contains an interior null byte", name)
     });
-    let val = unsafe { llvm::LLVMGetNamedValue(ccx.llmod(), namebuf.as_ptr()) };
+    let val = unsafe { llvm::LLVMRustGetNamedValue(ccx.llmod(), namebuf.as_ptr()) };
     if val.is_null() {
         debug!("get_declared_value: {:?} value is null", name);
         None
diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs
index 1e4a2748182..2f27aed065d 100644
--- a/src/librustc_trans/intrinsic.rs
+++ b/src/librustc_trans/intrinsic.rs
@@ -640,28 +640,30 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
         // This requires that atomic intrinsics follow a specific naming pattern:
         // "atomic_<operation>[_<ordering>]", and no ordering means SeqCst
         (_, name) if name.starts_with("atomic_") => {
+            use llvm::AtomicOrdering::*;
+
             let split: Vec<&str> = name.split('_').collect();
 
             let is_cxchg = split[1] == "cxchg" || split[1] == "cxchgweak";
             let (order, failorder) = match split.len() {
-                2 => (llvm::SequentiallyConsistent, llvm::SequentiallyConsistent),
+                2 => (SequentiallyConsistent, SequentiallyConsistent),
                 3 => match split[2] {
-                    "unordered" => (llvm::Unordered, llvm::Unordered),
-                    "relaxed" => (llvm::Monotonic, llvm::Monotonic),
-                    "acq"     => (llvm::Acquire, llvm::Acquire),
-                    "rel"     => (llvm::Release, llvm::Monotonic),
-                    "acqrel"  => (llvm::AcquireRelease, llvm::Acquire),
+                    "unordered" => (Unordered, Unordered),
+                    "relaxed" => (Monotonic, Monotonic),
+                    "acq"     => (Acquire, Acquire),
+                    "rel"     => (Release, Monotonic),
+                    "acqrel"  => (AcquireRelease, Acquire),
                     "failrelaxed" if is_cxchg =>
-                        (llvm::SequentiallyConsistent, llvm::Monotonic),
+                        (SequentiallyConsistent, Monotonic),
                     "failacq" if is_cxchg =>
-                        (llvm::SequentiallyConsistent, llvm::Acquire),
+                        (SequentiallyConsistent, Acquire),
                     _ => ccx.sess().fatal("unknown ordering in atomic intrinsic")
                 },
                 4 => match (split[2], split[3]) {
                     ("acq", "failrelaxed") if is_cxchg =>
-                        (llvm::Acquire, llvm::Monotonic),
+                        (Acquire, Monotonic),
                     ("acqrel", "failrelaxed") if is_cxchg =>
-                        (llvm::AcquireRelease, llvm::Monotonic),
+                        (AcquireRelease, Monotonic),
                     _ => ccx.sess().fatal("unknown ordering in atomic intrinsic")
                 },
                 _ => ccx.sess().fatal("Atomic intrinsic not in correct format"),
@@ -714,12 +716,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
                 }
 
                 "fence" => {
-                    AtomicFence(bcx, order, llvm::CrossThread);
+                    AtomicFence(bcx, order, llvm::SynchronizationScope::CrossThread);
                     C_nil(ccx)
                 }
 
                 "singlethreadfence" => {
-                    AtomicFence(bcx, order, llvm::SingleThread);
+                    AtomicFence(bcx, order, llvm::SynchronizationScope::SingleThread);
                     C_nil(ccx)
                 }
 
diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs
index 0221232a77d..8f723d288c9 100644
--- a/src/librustc_trans/mir/mod.rs
+++ b/src/librustc_trans/mir/mod.rs
@@ -324,8 +324,8 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
                         machine::llelement_offset(bcx.ccx(), lltuplety, i);
 
                     let ops = unsafe {
-                        [llvm::LLVMDIBuilderCreateOpDeref(),
-                         llvm::LLVMDIBuilderCreateOpPlus(),
+                        [llvm::LLVMRustDIBuilderCreateOpDeref(),
+                         llvm::LLVMRustDIBuilderCreateOpPlus(),
                          byte_offset_of_var_in_tuple as i64]
                     };
 
@@ -450,10 +450,10 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
                     machine::llelement_offset(bcx.ccx(), llclosurety, i);
 
                 let ops = unsafe {
-                    [llvm::LLVMDIBuilderCreateOpDeref(),
-                     llvm::LLVMDIBuilderCreateOpPlus(),
+                    [llvm::LLVMRustDIBuilderCreateOpDeref(),
+                     llvm::LLVMRustDIBuilderCreateOpPlus(),
                      byte_offset_of_var_in_env as i64,
-                     llvm::LLVMDIBuilderCreateOpDeref()]
+                     llvm::LLVMRustDIBuilderCreateOpDeref()]
                 };
 
                 // The environment and the capture can each be indirect.
diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs
index 001cd197e60..c09515a5138 100644
--- a/src/librustc_trans/type_.rs
+++ b/src/librustc_trans/type_.rs
@@ -36,7 +36,7 @@ pub struct Type {
 impl fmt::Debug for Type {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.write_str(&llvm::build_string(|s| unsafe {
-            llvm::LLVMWriteTypeToString(self.to_ref(), s);
+            llvm::LLVMRustWriteTypeToString(self.to_ref(), s);
         }).expect("non-UTF8 type description from LLVM"))
     }
 }
@@ -72,7 +72,7 @@ impl Type {
     }
 
     pub fn metadata(ccx: &CrateContext) -> Type {
-        ty!(llvm::LLVMMetadataTypeInContext(ccx.llcx()))
+        ty!(llvm::LLVMRustMetadataTypeInContext(ccx.llcx()))
     }
 
     pub fn i1(ccx: &CrateContext) -> Type {
diff --git a/src/librustc_trans/value.rs b/src/librustc_trans/value.rs
index 00b316cc420..79e0c11515f 100644
--- a/src/librustc_trans/value.rs
+++ b/src/librustc_trans/value.rs
@@ -23,7 +23,7 @@ pub struct Value(pub ValueRef);
 impl fmt::Debug for Value {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.write_str(&llvm::build_string(|s| unsafe {
-            llvm::LLVMWriteValueToString(self.0, s);
+            llvm::LLVMRustWriteValueToString(self.0, s);
         }).expect("nun-UTF8 value description from LLVM"))
     }
 }
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp
index bc38245d351..a9c31bc33e0 100644
--- a/src/rustllvm/RustWrapper.cpp
+++ b/src/rustllvm/RustWrapper.cpp
@@ -13,6 +13,7 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/IR/Instructions.h"
 
 #include "llvm/IR/CallSite.h"
 
@@ -27,6 +28,30 @@ using namespace llvm;
 using namespace llvm::sys;
 using namespace llvm::object;
 
+// LLVMAtomicOrdering is already an enum - don't create another
+// one.
+static AtomicOrdering from_rust(LLVMAtomicOrdering Ordering) {
+  switch (Ordering) {
+    case LLVMAtomicOrderingNotAtomic:
+        return AtomicOrdering::NotAtomic;
+    case LLVMAtomicOrderingUnordered:
+        return AtomicOrdering::Unordered;
+    case LLVMAtomicOrderingMonotonic:
+        return AtomicOrdering::Monotonic;
+    case LLVMAtomicOrderingAcquire:
+        return AtomicOrdering::Acquire;
+    case LLVMAtomicOrderingRelease:
+        return AtomicOrdering::Release;
+    case LLVMAtomicOrderingAcquireRelease:
+        return AtomicOrdering::AcquireRelease;
+    case LLVMAtomicOrderingSequentiallyConsistent:
+        return AtomicOrdering::SequentiallyConsistent;
+  }
+
+  llvm_unreachable("Invalid LLVMAtomicOrdering value!");
+}
+
+
 static char *LastError;
 
 extern "C" LLVMMemoryBufferRef
@@ -57,45 +82,30 @@ LLVMRustSetNormalizedTarget(LLVMModuleRef M, const char *triple) {
     unwrap(M)->setTargetTriple(Triple::normalize(triple));
 }
 
-extern "C" LLVMValueRef LLVMRustConstSmallInt(LLVMTypeRef IntTy, unsigned N,
-                                              LLVMBool SignExtend) {
-  return LLVMConstInt(IntTy, (unsigned long long)N, SignExtend);
-}
-
-extern "C" LLVMValueRef LLVMRustConstInt(LLVMTypeRef IntTy,
-           unsigned N_hi,
-           unsigned N_lo,
-           LLVMBool SignExtend) {
-  unsigned long long N = N_hi;
-  N <<= 32;
-  N |= N_lo;
-  return LLVMConstInt(IntTy, N, SignExtend);
-}
-
 extern "C" void LLVMRustPrintPassTimings() {
   raw_fd_ostream OS (2, false); // stderr.
   TimerGroup::printAll(OS);
 }
 
-extern "C" LLVMValueRef LLVMGetNamedValue(LLVMModuleRef M,
-                                          const char* Name) {
+extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M,
+					      const char* Name) {
     return wrap(unwrap(M)->getNamedValue(Name));
 }
 
-extern "C" LLVMValueRef LLVMGetOrInsertFunction(LLVMModuleRef M,
-                                                const char* Name,
-                                                LLVMTypeRef FunctionTy) {
+extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
+						    const char* Name,
+						    LLVMTypeRef FunctionTy) {
   return wrap(unwrap(M)->getOrInsertFunction(Name,
                                              unwrap<FunctionType>(FunctionTy)));
 }
 
-extern "C" LLVMValueRef LLVMGetOrInsertGlobal(LLVMModuleRef M,
-                                              const char* Name,
-                                              LLVMTypeRef Ty) {
+extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M,
+						  const char* Name,
+						  LLVMTypeRef Ty) {
   return wrap(unwrap(M)->getOrInsertGlobal(Name, unwrap(Ty)));
 }
 
-extern "C" LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) {
+extern "C" LLVMTypeRef LLVMRustMetadataTypeInContext(LLVMContextRef C) {
   return wrap(Type::getMetadataTy(*unwrap(C)));
 }
 
@@ -110,7 +120,10 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index,
 }
 
 
-extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned idx, uint64_t b) {
+extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
+						       unsigned idx,
+						       uint64_t b)
+{
   CallSite Call = CallSite(unwrap<Instruction>(Instr));
   AttrBuilder B;
   B.addDereferenceableAttr(b);
@@ -120,38 +133,50 @@ extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned
                                                          idx, B)));
 }
 
-extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index,
-                                         uint64_t Val) {
+extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn,
+					     unsigned index,
+					     uint64_t Val)
+{
   Function *A = unwrap<Function>(Fn);
   AttrBuilder B;
   B.addRawValue(Val);
   A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
 }
 
-extern "C" void LLVMAddDereferenceableAttr(LLVMValueRef Fn, unsigned index, uint64_t bytes) {
+extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn,
+					       unsigned index,
+					       uint64_t bytes)
+{
   Function *A = unwrap<Function>(Fn);
   AttrBuilder B;
   B.addDereferenceableAttr(bytes);
   A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
 }
 
-extern "C" void LLVMAddFunctionAttrString(LLVMValueRef Fn, unsigned index, const char *Name) {
+extern "C" void LLVMRustAddFunctionAttrString(LLVMValueRef Fn,
+					      unsigned index,
+					      const char *Name)
+{
   Function *F = unwrap<Function>(Fn);
   AttrBuilder B;
   B.addAttribute(Name);
   F->addAttributes(index, AttributeSet::get(F->getContext(), index, B));
 }
 
-extern "C" void LLVMAddFunctionAttrStringValue(LLVMValueRef Fn, unsigned index,
-                                               const char *Name,
-                                               const char *Value) {
+extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
+						   unsigned index,
+						   const char *Name,
+						   const char *Value) {
   Function *F = unwrap<Function>(Fn);
   AttrBuilder B;
   B.addAttribute(Name, Value);
   F->addAttributes(index, AttributeSet::get(F->getContext(), index, B));
 }
 
-extern "C" void LLVMRemoveFunctionAttributes(LLVMValueRef Fn, unsigned index, uint64_t Val) {
+extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
+						 unsigned index,
+						 uint64_t Val)
+{
   Function *A = unwrap<Function>(Fn);
   const AttributeSet PAL = A->getAttributes();
   AttrBuilder B(Val);
@@ -161,7 +186,10 @@ extern "C" void LLVMRemoveFunctionAttributes(LLVMValueRef Fn, unsigned index, ui
   A->setAttributes(PALnew);
 }
 
-extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, unsigned index, const char *Name) {
+extern "C" void LLVMRustRemoveFunctionAttrString(LLVMValueRef fn,
+						 unsigned index,
+						 const char *Name)
+{
   Function *f = unwrap<Function>(fn);
   LLVMContext &C = f->getContext();
   AttrBuilder B;
@@ -181,24 +209,24 @@ extern "C" void LLVMRustSetHasUnsafeAlgebra(LLVMValueRef V) {
     }
 }
 
-extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
-                                            LLVMValueRef source,
-                                            const char* Name,
-                                            AtomicOrdering order,
-                                            unsigned alignment) {
+extern "C" LLVMValueRef LLVMRustBuildAtomicLoad(LLVMBuilderRef B,
+						LLVMValueRef source,
+						const char* Name,
+						LLVMAtomicOrdering order,
+						unsigned alignment) {
     LoadInst* li = new LoadInst(unwrap(source),0);
-    li->setAtomic(order);
+    li->setAtomic(from_rust(order));
     li->setAlignment(alignment);
     return wrap(unwrap(B)->Insert(li, Name));
 }
 
-extern "C" LLVMValueRef LLVMBuildAtomicStore(LLVMBuilderRef B,
-                                             LLVMValueRef val,
-                                             LLVMValueRef target,
-                                             AtomicOrdering order,
-                                             unsigned alignment) {
+extern "C" LLVMValueRef LLVMRustBuildAtomicStore(LLVMBuilderRef B,
+						 LLVMValueRef val,
+						 LLVMValueRef target,
+						 LLVMAtomicOrdering order,
+						 unsigned alignment) {
     StoreInst* si = new StoreInst(unwrap(val),unwrap(target));
-    si->setAtomic(order);
+    si->setAtomic(from_rust(order));
     si->setAlignment(alignment);
     return wrap(unwrap(B)->Insert(si));
 }
@@ -207,54 +235,77 @@ extern "C" LLVMValueRef LLVMRustBuildAtomicCmpXchg(LLVMBuilderRef B,
                                                LLVMValueRef target,
                                                LLVMValueRef old,
                                                LLVMValueRef source,
-                                               AtomicOrdering order,
-                                               AtomicOrdering failure_order,
+                                               LLVMAtomicOrdering order,
+                                               LLVMAtomicOrdering failure_order,
                                                LLVMBool weak) {
-    AtomicCmpXchgInst* acxi = unwrap(B)->CreateAtomicCmpXchg(unwrap(target),
-                                                             unwrap(old),
-                                                             unwrap(source),
-                                                             order,
-                                                             failure_order);
+    AtomicCmpXchgInst* acxi = unwrap(B)->CreateAtomicCmpXchg(
+        unwrap(target),
+        unwrap(old),
+        unwrap(source),
+        from_rust(order),
+	from_rust(failure_order));
     acxi->setWeak(weak);
     return wrap(acxi);
 }
-extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B,
-                                             AtomicOrdering order,
-                                             SynchronizationScope scope) {
-    return wrap(unwrap(B)->CreateFence(order, scope));
+
+enum class LLVMRustSynchronizationScope {
+    Other,
+    SingleThread,
+    CrossThread,
+};
+
+static SynchronizationScope
+from_rust(LLVMRustSynchronizationScope scope)
+{
+    switch (scope) {
+    case LLVMRustSynchronizationScope::SingleThread:
+        return SingleThread;
+    case LLVMRustSynchronizationScope::CrossThread:
+        return CrossThread;
+    default:
+        abort();
+    }
+}
+
+extern "C" LLVMValueRef LLVMRustBuildAtomicFence(
+    LLVMBuilderRef B,
+    LLVMAtomicOrdering order,
+    LLVMRustSynchronizationScope scope)
+{
+    return wrap(unwrap(B)->CreateFence(from_rust(order), from_rust(scope)));
 }
 
-extern "C" void LLVMSetDebug(int Enabled) {
+extern "C" void LLVMRustSetDebug(int Enabled) {
 #ifndef NDEBUG
   DebugFlag = Enabled;
 #endif
 }
 
-extern "C" LLVMValueRef LLVMInlineAsm(LLVMTypeRef Ty,
-                                      char *AsmString,
-                                      char *Constraints,
-                                      LLVMBool HasSideEffects,
-                                      LLVMBool IsAlignStack,
-                                      unsigned Dialect) {
+extern "C" LLVMValueRef LLVMRustInlineAsm(LLVMTypeRef Ty,
+					  char *AsmString,
+					  char *Constraints,
+					  LLVMBool HasSideEffects,
+					  LLVMBool IsAlignStack,
+					  unsigned Dialect) {
     return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), AsmString,
                                Constraints, HasSideEffects,
                                IsAlignStack, (InlineAsm::AsmDialect) Dialect));
 }
 
-typedef DIBuilder* DIBuilderRef;
+typedef DIBuilder* LLVMRustDIBuilderRef;
 
-typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
+typedef struct LLVMOpaqueMetadata *LLVMRustMetadataRef;
 
 namespace llvm {
-DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef)
+DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMRustMetadataRef)
 
-inline Metadata **unwrap(LLVMMetadataRef *Vals) {
+inline Metadata **unwrap(LLVMRustMetadataRef *Vals) {
   return reinterpret_cast<Metadata**>(Vals);
 }
 }
 
 template<typename DIT>
-DIT* unwrapDIptr(LLVMMetadataRef ref) {
+DIT* unwrapDIptr(LLVMRustMetadataRef ref) {
     return (DIT*) (ref ? unwrap<MDNode>(ref) : NULL);
 }
 
@@ -266,11 +317,11 @@ extern "C" uint32_t LLVMRustDebugMetadataVersion() {
     return DEBUG_METADATA_VERSION;
 }
 
-extern "C" uint32_t LLVMVersionMinor() {
+extern "C" uint32_t LLVMRustVersionMinor() {
   return LLVM_VERSION_MINOR;
 }
 
-extern "C" uint32_t LLVMVersionMajor() {
+extern "C" uint32_t LLVMRustVersionMajor() {
   return LLVM_VERSION_MAJOR;
 }
 
@@ -280,20 +331,20 @@ extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
     unwrap(M)->addModuleFlag(Module::Warning, name, value);
 }
 
-extern "C" DIBuilderRef LLVMDIBuilderCreate(LLVMModuleRef M) {
+extern "C" LLVMRustDIBuilderRef LLVMRustDIBuilderCreate(LLVMModuleRef M) {
     return new DIBuilder(*unwrap(M));
 }
 
-extern "C" void LLVMDIBuilderDispose(DIBuilderRef Builder) {
+extern "C" void LLVMRustDIBuilderDispose(LLVMRustDIBuilderRef Builder) {
     delete Builder;
 }
 
-extern "C" void LLVMDIBuilderFinalize(DIBuilderRef Builder) {
+extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) {
     Builder->finalize();
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit(
+    LLVMRustDIBuilderRef Builder,
     unsigned Lang,
     const char* File,
     const char* Dir,
@@ -312,17 +363,17 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
                                            SplitName));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateFile(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFile(
+    LLVMRustDIBuilderRef Builder,
     const char* Filename,
     const char* Directory) {
     return wrap(Builder->createFile(Filename, Directory));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(
-    DIBuilderRef Builder,
-    LLVMMetadataRef File,
-    LLVMMetadataRef ParameterTypes) {
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateSubroutineType(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef File,
+    LLVMRustMetadataRef ParameterTypes) {
     return wrap(Builder->createSubroutineType(
 #if LLVM_VERSION_MINOR == 7
         unwrapDI<DIFile>(File),
@@ -330,22 +381,22 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(
         DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
     const char* Name,
     const char* LinkageName,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNo,
-    LLVMMetadataRef Ty,
+    LLVMRustMetadataRef Ty,
     bool isLocalToUnit,
     bool isDefinition,
     unsigned ScopeLine,
     unsigned Flags,
     bool isOptimized,
     LLVMValueRef Fn,
-    LLVMMetadataRef TParam,
-    LLVMMetadataRef Decl) {
+    LLVMRustMetadataRef TParam,
+    LLVMRustMetadataRef Decl) {
 #if LLVM_VERSION_MINOR >= 8
     DITemplateParameterArray TParams =
         DITemplateParameterArray(unwrap<MDTuple>(TParam));
@@ -370,8 +421,8 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction(
 #endif
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateBasicType(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateBasicType(
+    LLVMRustDIBuilderRef Builder,
     const char* Name,
     uint64_t SizeInBits,
     uint64_t AlignInBits,
@@ -381,9 +432,9 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateBasicType(
         AlignInBits, Encoding));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreatePointerType(
-    DIBuilderRef Builder,
-    LLVMMetadataRef PointeeTy,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreatePointerType(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef PointeeTy,
     uint64_t SizeInBits,
     uint64_t AlignInBits,
     const char* Name) {
@@ -391,19 +442,19 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreatePointerType(
         unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, Name));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateStructType(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStructType(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
     const char* Name,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNumber,
     uint64_t SizeInBits,
     uint64_t AlignInBits,
     unsigned Flags,
-    LLVMMetadataRef DerivedFrom,
-    LLVMMetadataRef Elements,
+    LLVMRustMetadataRef DerivedFrom,
+    LLVMRustMetadataRef Elements,
     unsigned RunTimeLang,
-    LLVMMetadataRef VTableHolder,
+    LLVMRustMetadataRef VTableHolder,
     const char *UniqueId) {
     return wrap(Builder->createStructType(
         unwrapDI<DIDescriptor>(Scope),
@@ -421,17 +472,17 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStructType(
         ));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateMemberType(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateMemberType(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
     const char* Name,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNo,
     uint64_t SizeInBits,
     uint64_t AlignInBits,
     uint64_t OffsetInBits,
     unsigned Flags,
-    LLVMMetadataRef Ty) {
+    LLVMRustMetadataRef Ty) {
     return wrap(Builder->createMemberType(
         unwrapDI<DIDescriptor>(Scope), Name,
         unwrapDI<DIFile>(File), LineNo,
@@ -439,10 +490,10 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateMemberType(
         unwrapDI<DIType>(Ty)));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
-    LLVMMetadataRef File,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateLexicalBlock(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
+    LLVMRustMetadataRef File,
     unsigned Line,
     unsigned Col) {
     return wrap(Builder->createLexicalBlock(
@@ -451,17 +502,17 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
         ));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateStaticVariable(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Context,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Context,
     const char* Name,
     const char* LinkageName,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNo,
-    LLVMMetadataRef Ty,
+    LLVMRustMetadataRef Ty,
     bool isLocalToUnit,
     LLVMValueRef Val,
-    LLVMMetadataRef Decl = NULL) {
+    LLVMRustMetadataRef Decl = NULL) {
     return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
         Name,
         LinkageName,
@@ -473,14 +524,14 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStaticVariable(
         unwrapDIptr<MDNode>(Decl)));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable(
+    LLVMRustDIBuilderRef Builder,
     unsigned Tag,
-    LLVMMetadataRef Scope,
+    LLVMRustMetadataRef Scope,
     const char* Name,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNo,
-    LLVMMetadataRef Ty,
+    LLVMRustMetadataRef Ty,
     bool AlwaysPreserve,
     unsigned Flags,
     int64_t* AddrOps,
@@ -509,50 +560,50 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable(
 #endif
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateArrayType(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateArrayType(
+    LLVMRustDIBuilderRef Builder,
     uint64_t Size,
     uint64_t AlignInBits,
-    LLVMMetadataRef Ty,
-    LLVMMetadataRef Subscripts) {
+    LLVMRustMetadataRef Ty,
+    LLVMRustMetadataRef Subscripts) {
     return wrap(Builder->createArrayType(Size, AlignInBits,
         unwrapDI<DIType>(Ty),
         DINodeArray(unwrapDI<MDTuple>(Subscripts))
     ));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateVectorType(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVectorType(
+    LLVMRustDIBuilderRef Builder,
     uint64_t Size,
     uint64_t AlignInBits,
-    LLVMMetadataRef Ty,
-    LLVMMetadataRef Subscripts) {
+    LLVMRustMetadataRef Ty,
+    LLVMRustMetadataRef Subscripts) {
     return wrap(Builder->createVectorType(Size, AlignInBits,
         unwrapDI<DIType>(Ty),
         DINodeArray(unwrapDI<MDTuple>(Subscripts))
     ));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderGetOrCreateSubrange(
+    LLVMRustDIBuilderRef Builder,
     int64_t Lo,
     int64_t Count) {
     return wrap(Builder->getOrCreateSubrange(Lo, Count));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(
-    DIBuilderRef Builder,
-    LLVMMetadataRef* Ptr,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderGetOrCreateArray(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef* Ptr,
     unsigned Count) {
     Metadata **DataValue = unwrap(Ptr);
     return wrap(Builder->getOrCreateArray(
         ArrayRef<Metadata*>(DataValue, Count)).get());
 }
 
-extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
-    DIBuilderRef Builder,
+extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
+    LLVMRustDIBuilderRef Builder,
     LLVMValueRef Val,
-    LLVMMetadataRef VarInfo,
+    LLVMRustMetadataRef VarInfo,
     int64_t* AddrOps,
     unsigned AddrOpsCount,
     LLVMValueRef DL,
@@ -566,10 +617,10 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
         unwrap(InsertAtEnd)));
 }
 
-extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
-    DIBuilderRef Builder,
+extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareBefore(
+    LLVMRustDIBuilderRef Builder,
     LLVMValueRef Val,
-    LLVMMetadataRef VarInfo,
+    LLVMRustMetadataRef VarInfo,
     int64_t* AddrOps,
     unsigned AddrOpsCount,
     LLVMValueRef DL,
@@ -583,24 +634,24 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
         unwrap<Instruction>(InsertBefore)));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateEnumerator(
-    DIBuilderRef Builder,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerator(
+    LLVMRustDIBuilderRef Builder,
     const char* Name,
     uint64_t Val)
 {
     return wrap(Builder->createEnumerator(Name, Val));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerationType(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
     const char* Name,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNumber,
     uint64_t SizeInBits,
     uint64_t AlignInBits,
-    LLVMMetadataRef Elements,
-    LLVMMetadataRef ClassType)
+    LLVMRustMetadataRef Elements,
+    LLVMRustMetadataRef ClassType)
 {
     return wrap(Builder->createEnumerationType(
         unwrapDI<DIDescriptor>(Scope),
@@ -613,16 +664,16 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
         unwrapDI<DIType>(ClassType)));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
     const char* Name,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNumber,
     uint64_t SizeInBits,
     uint64_t AlignInBits,
     unsigned Flags,
-    LLVMMetadataRef Elements,
+    LLVMRustMetadataRef Elements,
     unsigned RunTimeLang,
     const char* UniqueId)
 {
@@ -640,12 +691,12 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType(
         ));
 }
 
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateTemplateTypeParameter(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
     const char* Name,
-    LLVMMetadataRef Ty,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef Ty,
+    LLVMRustMetadataRef File,
     unsigned LineNo,
     unsigned ColumnNo)
 {
@@ -656,21 +707,11 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateTemplateTypeParameter(
       ));
 }
 
-extern "C" int64_t LLVMDIBuilderCreateOpDeref()
-{
-    return dwarf::DW_OP_deref;
-}
-
-extern "C" int64_t LLVMDIBuilderCreateOpPlus()
-{
-    return dwarf::DW_OP_plus;
-}
-
-extern "C" LLVMMetadataRef LLVMDIBuilderCreateNameSpace(
-    DIBuilderRef Builder,
-    LLVMMetadataRef Scope,
+extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateNameSpace(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef Scope,
     const char* Name,
-    LLVMMetadataRef File,
+    LLVMRustMetadataRef File,
     unsigned LineNo)
 {
     return wrap(Builder->createNameSpace(
@@ -680,22 +721,22 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateNameSpace(
         LineNo));
 }
 
-extern "C" void LLVMDICompositeTypeSetTypeArray(
-    DIBuilderRef Builder,
-    LLVMMetadataRef CompositeType,
-    LLVMMetadataRef TypeArray)
+extern "C" void LLVMRustDICompositeTypeSetTypeArray(
+    LLVMRustDIBuilderRef Builder,
+    LLVMRustMetadataRef CompositeType,
+    LLVMRustMetadataRef TypeArray)
 {
     DICompositeType *tmp = unwrapDI<DICompositeType>(CompositeType);
     Builder->replaceArrays(tmp, DINodeArray(unwrap<MDTuple>(TypeArray)));
 }
 
-extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation(
+extern "C" LLVMValueRef LLVMRustDIBuilderCreateDebugLocation(
   LLVMContextRef Context,
   unsigned Line,
   unsigned Column,
-  LLVMMetadataRef Scope,
-  LLVMMetadataRef InlinedAt) {
-
+  LLVMRustMetadataRef Scope,
+  LLVMRustMetadataRef InlinedAt)
+{
     LLVMContext& context = *unwrap(Context);
 
     DebugLoc debug_loc = DebugLoc::get(Line,
@@ -706,12 +747,22 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation(
     return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode()));
 }
 
-extern "C" void LLVMWriteTypeToString(LLVMTypeRef Type, RustStringRef str) {
+extern "C" int64_t LLVMRustDIBuilderCreateOpDeref()
+{
+    return dwarf::DW_OP_deref;
+}
+
+extern "C" int64_t LLVMRustDIBuilderCreateOpPlus()
+{
+    return dwarf::DW_OP_plus;
+}
+
+extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Type, RustStringRef str) {
     raw_rust_string_ostream os(str);
     unwrap<llvm::Type>(Type)->print(os);
 }
 
-extern "C" void LLVMWriteValueToString(LLVMValueRef Value, RustStringRef str) {
+extern "C" void LLVMRustWriteValueToString(LLVMValueRef Value, RustStringRef str) {
     raw_rust_string_ostream os(str);
     os << "(";
     unwrap<llvm::Value>(Value)->getType()->print(os);
@@ -746,11 +797,33 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
     return true;
 }
 
+enum class LLVMRustDLLStorageClassTypes {
+    Other,
+    Default,
+    DllImport,
+    DllExport,
+};
+
+static GlobalValue::DLLStorageClassTypes
+from_rust(LLVMRustDLLStorageClassTypes Class)
+{
+    switch (Class) {
+    case LLVMRustDLLStorageClassTypes::Default:
+        return GlobalValue::DefaultStorageClass;
+    case LLVMRustDLLStorageClassTypes::DllImport:
+        return GlobalValue::DLLImportStorageClass;
+    case LLVMRustDLLStorageClassTypes::DllExport:
+        return GlobalValue::DLLExportStorageClass;
+    default:
+        abort();
+  }
+}
+
 extern "C" void
 LLVMRustSetDLLStorageClass(LLVMValueRef Value,
-                           GlobalValue::DLLStorageClassTypes Class) {
+                           LLVMRustDLLStorageClassTypes Class) {
     GlobalValue *V = unwrap<GlobalValue>(Value);
-    V->setDLLStorageClass(Class);
+    V->setDLLStorageClass(from_rust(Class));
 }
 
 // Note that the two following functions look quite similar to the
@@ -768,7 +841,7 @@ inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
     return reinterpret_cast<section_iterator*>(SI);
 }
 
-extern "C" int
+extern "C" size_t
 LLVMRustGetSectionName(LLVMSectionIteratorRef SI, const char **ptr) {
     StringRef ret;
     if (std::error_code ec = (*unwrap(SI))->getName(ret))
@@ -787,13 +860,13 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Twine, LLVMTwineRef)
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DebugLoc, LLVMDebugLocRef)
 
 extern "C" void
-LLVMWriteTwineToString(LLVMTwineRef T, RustStringRef str) {
+LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef str) {
     raw_rust_string_ostream os(str);
     unwrap(T)->print(os);
 }
 
 extern "C" void
-LLVMUnpackOptimizationDiagnostic(
+LLVMRustUnpackOptimizationDiagnostic(
     LLVMDiagnosticInfoRef di,
     const char **pass_name_out,
     LLVMValueRef *function_out,
@@ -811,7 +884,7 @@ LLVMUnpackOptimizationDiagnostic(
 }
 
 extern "C" void
-LLVMUnpackInlineAsmDiagnostic(
+LLVMRustUnpackInlineAsmDiagnostic(
     LLVMDiagnosticInfoRef di,
     unsigned *cookie_out,
     LLVMTwineRef *message_out,
@@ -826,17 +899,68 @@ LLVMUnpackInlineAsmDiagnostic(
     *instruction_out = wrap(ia->getInstruction());
 }
 
-extern "C" void LLVMWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef di, RustStringRef str) {
+extern "C" void LLVMRustWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef di, RustStringRef str) {
     raw_rust_string_ostream os(str);
     DiagnosticPrinterRawOStream dp(os);
     unwrap(di)->print(dp);
 }
 
-extern "C" int LLVMGetDiagInfoKind(LLVMDiagnosticInfoRef di) {
-    return unwrap(di)->getKind();
+enum class LLVMRustDiagnosticKind {
+    Other,
+    InlineAsm,
+    StackSize,
+    DebugMetadataVersion,
+    SampleProfile,
+    OptimizationRemark,
+    OptimizationRemarkMissed,
+    OptimizationRemarkAnalysis,
+    OptimizationRemarkAnalysisFPCommute,
+    OptimizationRemarkAnalysisAliasing,
+    OptimizationRemarkOther,
+    OptimizationFailure,
+};
+
+static LLVMRustDiagnosticKind
+to_rust(DiagnosticKind kind)
+{
+    switch (kind) {
+    case DK_InlineAsm:
+        return LLVMRustDiagnosticKind::InlineAsm;
+    case DK_StackSize:
+        return LLVMRustDiagnosticKind::StackSize;
+    case DK_DebugMetadataVersion:
+        return LLVMRustDiagnosticKind::DebugMetadataVersion;
+    case DK_SampleProfile:
+        return LLVMRustDiagnosticKind::SampleProfile;
+    case DK_OptimizationRemark:
+        return LLVMRustDiagnosticKind::OptimizationRemark;
+    case DK_OptimizationRemarkMissed:
+        return LLVMRustDiagnosticKind::OptimizationRemarkMissed;
+    case DK_OptimizationRemarkAnalysis:
+        return LLVMRustDiagnosticKind::OptimizationRemarkAnalysis;
+#if LLVM_VERSION_MINOR >= 8
+    case DK_OptimizationRemarkAnalysisFPCommute:
+        return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute;
+    case DK_OptimizationRemarkAnalysisAliasing:
+        return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing;
+#endif
+    default:
+#if LLVM_VERSION_MINOR >= 9
+        return (kind >= DK_FirstRemark && kind <= DK_LastRemark) ?
+            LLVMRustDiagnosticKind::OptimizationRemarkOther :
+            LLVMRustDiagnosticKind::Other;
+#else
+        return LLVMRustDiagnosticKind::Other;
+#endif
+  }
+}
+
+
+extern "C" LLVMRustDiagnosticKind LLVMRustGetDiagInfoKind(LLVMDiagnosticInfoRef di) {
+    return to_rust((DiagnosticKind) unwrap(di)->getKind());
 }
 
-extern "C" void LLVMWriteDebugLocToString(
+extern "C" void LLVMRustWriteDebugLocToString(
     LLVMContextRef C,
     LLVMDebugLocRef dl,
     RustStringRef str)
@@ -847,7 +971,8 @@ extern "C" void LLVMWriteDebugLocToString(
 
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef)
 
-extern "C" void LLVMSetInlineAsmDiagnosticHandler(
+// FIXME(type-audit): assume this function-pointer type does not change
+extern "C" void LLVMRustSetInlineAsmDiagnosticHandler(
     LLVMContextRef C,
     LLVMContext::InlineAsmDiagHandlerTy H,
     void *CX)
@@ -855,7 +980,8 @@ extern "C" void LLVMSetInlineAsmDiagnosticHandler(
     unwrap(C)->setInlineAsmDiagnosticHandler(H, CX);
 }
 
-extern "C" void LLVMWriteSMDiagnosticToString(LLVMSMDiagnosticRef d, RustStringRef str) {
+extern "C" void LLVMRustWriteSMDiagnosticToString(LLVMSMDiagnosticRef d,
+						  RustStringRef str) {
     raw_rust_string_ostream os(str);
     unwrap(d)->print("", os);
 }
@@ -902,6 +1028,8 @@ LLVMRustBuildCleanupRet(LLVMBuilderRef Builder,
 #endif
 }
 
+// FIXME: to here.
+
 extern "C" LLVMValueRef
 LLVMRustBuildCatchPad(LLVMBuilderRef Builder,
                       LLVMValueRef ParentPad,