about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorDenis Merigoux <denis.merigoux@gmail.com>2018-09-06 18:31:42 -0700
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 14:11:59 +0200
commitc487b825b0a59b3e4c758a79f041245b79f4bf4f (patch)
tree61c07bd694c62db8c58dc971900dc321fca63ae5 /src/librustc_codegen_llvm
parent1929ac2007f835a3a46ef1e4b23e9512db007b35 (diff)
downloadrust-c487b825b0a59b3e4c758a79f041245b79f4bf4f.tar.gz
rust-c487b825b0a59b3e4c758a79f041245b79f4bf4f.zip
Attempt at including CodegenCx within Builder with Associated types
Diffstat (limited to 'src/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/base.rs2
-rw-r--r--src/librustc_codegen_llvm/builder.rs64
-rw-r--r--src/librustc_codegen_llvm/common.rs6
-rw-r--r--src/librustc_codegen_llvm/interfaces/builder.rs21
4 files changed, 52 insertions, 41 deletions
diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs
index 6257d32527f..7d3b6025e2a 100644
--- a/src/librustc_codegen_llvm/base.rs
+++ b/src/librustc_codegen_llvm/base.rs
@@ -157,7 +157,7 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
     }
 }
 
-pub fn compare_simd_types<'a, 'll:'a, 'tcx:'ll, Builder: BuilderMethods<'a, 'll, 'tcx>>(
+pub fn compare_simd_types<'a, 'tcx: 'a, Builder: BuilderMethods<'a, 'tcx>>(
     bx: &Builder,
     lhs: Builder::Value,
     rhs: Builder::Value,
diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs
index 10165c20860..2d5468cfc8e 100644
--- a/src/librustc_codegen_llvm/builder.rs
+++ b/src/librustc_codegen_llvm/builder.rs
@@ -12,7 +12,7 @@ use llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect};
 use llvm::{self, False, OperandBundleDef, BasicBlock};
 use common::{self, *};
 use context::CodegenCx;
-use type_;
+use type_::Type;
 use value::Value;
 use libc::{c_uint, c_char};
 use rustc::ty::TyCtxt;
@@ -57,14 +57,16 @@ bitflags! {
 }
 
 impl Backend for Builder<'a, 'll, 'tcx>  {
-        type Value = &'ll Value;
-        type BasicBlock = &'ll BasicBlock;
-        type Type = &'ll type_::Type;
-        type TypeKind = llvm::TypeKind;
-        type Context = &'ll llvm::Context;
+    type Value = &'ll Value;
+    type BasicBlock = &'ll BasicBlock;
+    type Type = &'ll Type;
+    type TypeKind = llvm::TypeKind;
+    type Context = &'ll llvm::Context;
 }
 
-impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
+impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
+    type CodegenCx = CodegenCx<'ll, 'tcx>;
+
     fn new_block<'b>(
         cx: &'a CodegenCx<'ll, 'tcx>,
         llfn: &'ll Value,
@@ -199,7 +201,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
                   args: &[&'ll Value],
                   then: &'ll BasicBlock,
                   catch: &'ll BasicBlock,
-                  bundle: Option<&common::OperandBundleDef<'ll, &'ll Value>>) -> &'ll Value {
+                  bundle: Option<&common::OperandBundleDef<&'ll Value>>) -> &'ll Value {
         self.count_insn("invoke");
 
         debug!("Invoke {:?} with args ({:?})",
@@ -437,7 +439,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
         }
     }
 
-    fn alloca(&self, ty: Self::Type, name: &str, align: Align) -> &'ll Value {
+    fn alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
         let bx = Builder::with_cx(self.cx);
         bx.position_at_start(unsafe {
             llvm::LLVMGetFirstBasicBlock(self.llfn())
@@ -445,7 +447,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
         bx.dynamic_alloca(ty, name, align)
     }
 
-    fn dynamic_alloca(&self, ty: Self::Type, name: &str, align: Align) -> &'ll Value {
+    fn dynamic_alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
         self.count_insn("alloca");
         unsafe {
             let alloca = if name.is_empty() {
@@ -461,7 +463,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
     }
 
     fn array_alloca(&self,
-                        ty: Self::Type,
+                        ty: &'ll Type,
                         len: &'ll Value,
                         name: &str,
                         align: Align) -> &'ll Value {
@@ -620,77 +622,77 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
     }
 
     /* Casts */
-    fn trunc(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn trunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("trunc");
         unsafe {
             llvm::LLVMBuildTrunc(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn sext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn sext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("sext");
         unsafe {
             llvm::LLVMBuildSExt(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn fptoui(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn fptoui(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("fptoui");
         unsafe {
             llvm::LLVMBuildFPToUI(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn fptosi(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn fptosi(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("fptosi");
         unsafe {
             llvm::LLVMBuildFPToSI(self.llbuilder, val, dest_ty,noname())
         }
     }
 
-    fn uitofp(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn uitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("uitofp");
         unsafe {
             llvm::LLVMBuildUIToFP(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn sitofp(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn sitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("sitofp");
         unsafe {
             llvm::LLVMBuildSIToFP(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn fptrunc(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn fptrunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("fptrunc");
         unsafe {
             llvm::LLVMBuildFPTrunc(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn fpext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn fpext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("fpext");
         unsafe {
             llvm::LLVMBuildFPExt(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn ptrtoint(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn ptrtoint(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("ptrtoint");
         unsafe {
             llvm::LLVMBuildPtrToInt(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn inttoptr(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn inttoptr(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("inttoptr");
         unsafe {
             llvm::LLVMBuildIntToPtr(self.llbuilder, val, dest_ty, noname())
         }
     }
 
-    fn bitcast(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn bitcast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("bitcast");
         unsafe {
             llvm::LLVMBuildBitCast(self.llbuilder, val, dest_ty, noname())
@@ -698,14 +700,14 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
     }
 
 
-    fn intcast(&self, val: &'ll Value, dest_ty: Self::Type, is_signed: bool) -> &'ll Value {
+    fn intcast(&self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value {
         self.count_insn("intcast");
         unsafe {
             llvm::LLVMRustBuildIntCast(self.llbuilder, val, dest_ty, is_signed)
         }
     }
 
-    fn pointercast(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn pointercast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("pointercast");
         unsafe {
             llvm::LLVMBuildPointerCast(self.llbuilder, val, dest_ty, noname())
@@ -729,14 +731,14 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
     }
 
     /* Miscellaneous instructions */
-    fn empty_phi(&self, ty: Self::Type) -> &'ll Value {
+    fn empty_phi(&self, ty: &'ll Type) -> &'ll Value {
         self.count_insn("emptyphi");
         unsafe {
             llvm::LLVMBuildPhi(self.llbuilder, ty, noname())
         }
     }
 
-    fn phi(&self, ty: Self::Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
+    fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
         assert_eq!(vals.len(), bbs.len());
         let phi = self.empty_phi(ty);
         self.count_insn("addincoming");
@@ -749,7 +751,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
     }
 
     fn inline_asm_call(&self, asm: *const c_char, cons: *const c_char,
-                       inputs: &[&'ll Value], output: Self::Type,
+                       inputs: &[&'ll Value], output: &'ll Type,
                        volatile: bool, alignstack: bool,
                        dia: syntax::ast::AsmDialect) -> Option<&'ll Value> {
         self.count_insn("inlineasm");
@@ -826,7 +828,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
     }
 
     #[allow(dead_code)]
-    fn va_arg(&self, list: &'ll Value, ty: Self::Type) -> &'ll Value {
+    fn va_arg(&self, list: &'ll Value, ty: &'ll Type) -> &'ll Value {
         self.count_insn("vaarg");
         unsafe {
             llvm::LLVMBuildVAArg(self.llbuilder, list, ty, noname())
@@ -961,7 +963,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
         }
     }
 
-    fn landing_pad(&self, ty: Self::Type, pers_fn: &'ll Value,
+    fn landing_pad(&self, ty: &'ll Type, pers_fn: &'ll Value,
                        num_clauses: usize) -> &'ll Value {
         self.count_insn("landingpad");
         unsafe {
@@ -1232,7 +1234,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
     }
 
     fn call(&self, llfn: &'ll Value, args: &[&'ll Value],
-                bundle: Option<&common::OperandBundleDef<'ll, &'ll Value>>) -> &'ll Value {
+                bundle: Option<&common::OperandBundleDef<&'ll Value>>) -> &'ll Value {
         self.count_insn("call");
 
         debug!("Call {:?} with args ({:?})",
@@ -1254,7 +1256,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
         }
     }
 
-    fn zext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
+    fn zext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
         self.count_insn("zext");
         unsafe {
             llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, noname())
diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs
index 6783807e563..19636596cea 100644
--- a/src/librustc_codegen_llvm/common.rs
+++ b/src/librustc_codegen_llvm/common.rs
@@ -50,13 +50,13 @@ pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bo
     ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
 }
 
-pub struct OperandBundleDef<'a, Value: 'a> {
+pub struct OperandBundleDef<'a, Value> {
     pub name: &'a str,
     pub val: Value
 }
 
-impl OperandBundleDef<'ll, &'ll Value> {
-    pub fn new(name: &'ll str, val: &'ll Value) -> Self {
+impl<'a, Value> OperandBundleDef<'a, Value> {
+    pub fn new(name: &'a str, val: Value) -> Self {
         OperandBundleDef {
             name,
             val
diff --git a/src/librustc_codegen_llvm/interfaces/builder.rs b/src/librustc_codegen_llvm/interfaces/builder.rs
index 143de3c5b07..867e91ff192 100644
--- a/src/librustc_codegen_llvm/interfaces/builder.rs
+++ b/src/librustc_codegen_llvm/interfaces/builder.rs
@@ -15,6 +15,8 @@ use rustc::ty::layout::{Align, Size};
 use rustc::session::Session;
 use builder::MemFlags;
 use super::backend::Backend;
+use super::type_::TypeMethods;
+use super::consts::ConstMethods;
 
 use std::borrow::Cow;
 use std::ops::Range;
@@ -22,17 +24,24 @@ use syntax::ast::AsmDialect;
 
 
 
-pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll>: Backend {
+pub trait BuilderMethods<'a, 'tcx: 'a>: Backend {
+    type CodegenCx: TypeMethods + ConstMethods + Backend<
+        Value = Self::Value,
+        BasicBlock = Self::BasicBlock,
+        Type = Self::Type,
+        TypeKind = Self::TypeKind,
+        Context = Self::Context,
+    >;
 
     fn new_block<'b>(
-        cx: &'a CodegenCx<'ll, 'tcx, Self::Value>,
+        cx: &'a Self::CodegenCx,
         llfn: Self::Value,
         name: &'b str
     ) -> Self;
-    fn with_cx(cx: &'a CodegenCx<'ll, 'tcx, Self::Value>) -> Self;
+    fn with_cx(cx: &'a Self::CodegenCx) -> Self;
     fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
     fn sess(&self) -> &Session;
-    fn cx(&self) -> &'a CodegenCx<'ll, 'tcx, Self::Value>;
+    fn cx(&self) -> &'a Self::CodegenCx;
     fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
     fn llfn(&self) -> Self::Value;
     fn llbb(&self) -> Self::BasicBlock;
@@ -62,7 +71,7 @@ pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll>: Backend {
         args: &[Self::Value],
         then: Self::BasicBlock,
         catch: Self::BasicBlock,
-        bundle: Option<&OperandBundleDef<'ll, Self::Value>>
+        bundle: Option<&OperandBundleDef<Self::Value>>
     ) -> Self::Value;
     fn unreachable(&self);
     fn add(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
@@ -278,6 +287,6 @@ pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll>: Backend {
     fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: Self::Value, size: Size);
 
     fn call(&self, llfn: Self::Value, args: &[Self::Value],
-                bundle: Option<&OperandBundleDef<'ll, Self::Value>>) -> Self::Value;
+                bundle: Option<&OperandBundleDef<Self::Value>>) -> Self::Value;
     fn zext(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
 }