about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-03-01 15:03:48 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2019-03-29 17:17:12 +0100
commit83e80a74436179588703db2d597e80f57e42efbe (patch)
treea99377db3900fe97454377daf4a455e2a96fc75a /src/librustc_codegen_ssa
parenta0c2ca1b56e64f4a5658ae0371da44e7af7cd58f (diff)
downloadrust-83e80a74436179588703db2d597e80f57e42efbe.tar.gz
rust-83e80a74436179588703db2d597e80f57e42efbe.zip
Use Builder instead of CodegenCx for OperandRef and LocalRef
Diffstat (limited to 'src/librustc_codegen_ssa')
-rw-r--r--src/librustc_codegen_ssa/mir/mod.rs14
-rw-r--r--src/librustc_codegen_ssa/mir/operand.rs30
-rw-r--r--src/librustc_codegen_ssa/mir/rvalue.rs7
3 files changed, 27 insertions, 24 deletions
diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs
index b0f53de17ea..5e2144751c1 100644
--- a/src/librustc_codegen_ssa/mir/mod.rs
+++ b/src/librustc_codegen_ssa/mir/mod.rs
@@ -178,16 +178,16 @@ enum LocalRef<'tcx, V> {
     Operand(Option<OperandRef<'tcx, V>>),
 }
 
-impl<'tcx, V: CodegenObject> LocalRef<'tcx, V> {
-    fn new_operand<Cx: CodegenMethods<'tcx, Value = V>>(
-        cx: &Cx,
+impl<'a, 'tcx: 'a, V: CodegenObject> LocalRef<'tcx, V> {
+    fn new_operand<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
+        bx: &mut Bx,
         layout: TyLayout<'tcx>,
     ) -> LocalRef<'tcx, V> {
         if layout.is_zst() {
             // Zero-size temporaries aren't always initialized, which
             // doesn't matter because they don't contain data, but
             // we need something in the operand.
-            LocalRef::Operand(Some(OperandRef::new_zst(cx, layout)))
+            LocalRef::Operand(Some(OperandRef::new_zst(bx, layout)))
         } else {
             LocalRef::Operand(None)
         }
@@ -275,7 +275,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
 
                 if !memory_locals.contains(local) && !dbg {
                     debug!("alloc: {:?} ({}) -> operand", local, name);
-                    return LocalRef::new_operand(bx.cx(), layout);
+                    return LocalRef::new_operand(&mut bx, layout);
                 }
 
                 debug!("alloc: {:?} ({}) -> place", local, name);
@@ -320,7 +320,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
                     // alloca in advance. Instead we wait until we see the
                     // definition and update the operand there.
                     debug!("alloc: {:?} -> operand", local);
-                    LocalRef::new_operand(bx.cx(), layout)
+                    LocalRef::new_operand(&mut bx, layout)
                 }
             }
         };
@@ -529,7 +529,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
             let local = |op| LocalRef::Operand(Some(op));
             match arg.mode {
                 PassMode::Ignore(IgnoreMode::Zst) => {
-                    return local(OperandRef::new_zst(bx.cx(), arg.layout));
+                    return local(OperandRef::new_zst(bx, arg.layout));
                 }
                 PassMode::Ignore(IgnoreMode::CVarArgs) => {}
                 PassMode::Direct(_) => {
diff --git a/src/librustc_codegen_ssa/mir/operand.rs b/src/librustc_codegen_ssa/mir/operand.rs
index 289129e8e62..c2b1021f816 100644
--- a/src/librustc_codegen_ssa/mir/operand.rs
+++ b/src/librustc_codegen_ssa/mir/operand.rs
@@ -54,13 +54,13 @@ impl<V: CodegenObject> fmt::Debug for OperandRef<'tcx, V> {
 }
 
 impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
-    pub fn new_zst<Cx: CodegenMethods<'tcx, Value = V>>(
-        cx: &Cx,
+    pub fn new_zst<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
+        bx: &mut Bx,
         layout: TyLayout<'tcx>
     ) -> OperandRef<'tcx, V> {
         assert!(layout.is_zst());
         OperandRef {
-            val: OperandValue::Immediate(cx.const_undef(cx.immediate_backend_type(layout))),
+            val: OperandValue::Immediate(bx.const_undef(bx.immediate_backend_type(layout))),
             layout
         }
     }
@@ -69,10 +69,10 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
         bx: &mut Bx,
         val: ty::Const<'tcx>
     ) -> Result<Self, ErrorHandled> {
-        let layout = bx.cx().layout_of(val.ty);
+        let layout = bx.layout_of(val.ty);
 
         if layout.is_zst() {
-            return Ok(OperandRef::new_zst(bx.cx(), layout));
+            return Ok(OperandRef::new_zst(bx, layout));
         }
 
         let val = match val.val {
@@ -84,10 +84,10 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
                     layout::Abi::Scalar(ref x) => x,
                     _ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
                 };
-                let llval = bx.cx().scalar_to_backend(
+                let llval = bx.scalar_to_backend(
                     x,
                     scalar,
-                    bx.cx().immediate_backend_type(layout),
+                    bx.immediate_backend_type(layout),
                 );
                 OperandValue::Immediate(llval)
             },
@@ -96,16 +96,16 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
                     layout::Abi::ScalarPair(ref a, _) => a,
                     _ => bug!("from_const: invalid ScalarPair layout: {:#?}", layout)
                 };
-                let a_llval = bx.cx().scalar_to_backend(
+                let a_llval = bx.scalar_to_backend(
                     a,
                     a_scalar,
-                    bx.cx().scalar_pair_element_backend_type(layout, 0, true),
+                    bx.scalar_pair_element_backend_type(layout, 0, true),
                 );
-                let b_llval = bx.cx().const_usize(b);
+                let b_llval = bx.const_usize(b);
                 OperandValue::Pair(a_llval, b_llval)
             },
             ConstValue::ByRef(ptr, alloc) => {
-                return Ok(bx.load_operand(bx.cx().from_const_alloc(layout, alloc, ptr.offset)));
+                return Ok(bx.load_operand(bx.from_const_alloc(layout, alloc, ptr.offset)));
             },
         };
 
@@ -124,7 +124,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
         }
     }
 
-    pub fn deref<Cx: CodegenMethods<'tcx, Value = V>>(
+    pub fn deref<Cx: LayoutTypeMethods<'tcx>>(
         self,
         cx: &Cx
     ) -> PlaceRef<'tcx, V> {
@@ -199,7 +199,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
         let mut val = match (self.val, &self.layout.abi) {
             // If the field is ZST, it has no data.
             _ if field.is_zst() => {
-                return OperandRef::new_zst(bx.cx(), field);
+                return OperandRef::new_zst(bx, field);
             }
 
             // Newtype of a scalar, scalar pair or vector.
@@ -409,7 +409,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                         // checks in `codegen_consume` and `extract_field`.
                         let elem = o.layout.field(bx.cx(), 0);
                         if elem.is_zst() {
-                            return Some(OperandRef::new_zst(bx.cx(), elem));
+                            return Some(OperandRef::new_zst(bx, elem));
                         }
                     }
                     _ => {}
@@ -432,7 +432,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
 
         // ZSTs don't require any actual memory access.
         if layout.is_zst() {
-            return OperandRef::new_zst(bx.cx(), layout);
+            return OperandRef::new_zst(bx, layout);
         }
 
         if let Some(o) = self.maybe_codegen_consume_direct(bx, place) {
diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs
index b8131671320..c20d3f44bc5 100644
--- a/src/librustc_codegen_ssa/mir/rvalue.rs
+++ b/src/librustc_codegen_ssa/mir/rvalue.rs
@@ -523,8 +523,11 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                 // According to `rvalue_creates_operand`, only ZST
                 // aggregate rvalues are allowed to be operands.
                 let ty = rvalue.ty(self.mir, self.cx.tcx());
-                (bx, OperandRef::new_zst(self.cx,
-                    self.cx.layout_of(self.monomorphize(&ty))))
+                let operand = OperandRef::new_zst(
+                    &mut bx,
+                    self.cx.layout_of(self.monomorphize(&ty)),
+                );
+                (bx, operand)
             }
         }
     }