]> git.lizzy.rs Git - rust.git/commitdiff
trans: Take a &Builder in call_memcpy, like call_memset.
authorEduard Burtescu <edy.burt@gmail.com>
Tue, 8 Mar 2016 12:29:46 +0000 (14:29 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Thu, 17 Mar 2016 19:51:54 +0000 (21:51 +0200)
src/librustc_trans/trans/abi.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/callee.rs
src/librustc_trans/trans/tvec.rs

index 62b6c24d38747db68811283b316c5b1104ea7c5c..46a76b609892bbb04c923a72cb389588dbef4722 100644 (file)
@@ -10,7 +10,8 @@
 
 use llvm::{self, ValueRef};
 use trans::base;
-use trans::build::*;
+use trans::build::B;
+use trans::builder::Builder;
 use trans::common::{type_is_fat_ptr, Block};
 use trans::context::CrateContext;
 use trans::cabi_x86;
@@ -145,27 +146,26 @@ pub fn memory_ty(&self, ccx: &CrateContext) -> Type {
     /// lvalue for the original Rust type of this argument/return.
     /// Can be used for both storing formal arguments into Rust variables
     /// or results of call/invoke instructions into their destinations.
-    pub fn store(&self, bcx: Block, mut val: ValueRef, dst: ValueRef) {
+    pub fn store(&self, b: &Builder, mut val: ValueRef, dst: ValueRef) {
         if self.is_ignore() {
             return;
         }
         if self.is_indirect() {
-            let llsz = llsize_of(bcx.ccx(), self.ty);
-            let llalign = llalign_of_min(bcx.ccx(), self.ty);
-            base::call_memcpy(bcx, dst, val, llsz, llalign as u32);
+            let llsz = llsize_of(b.ccx, self.ty);
+            let llalign = llalign_of_min(b.ccx, self.ty);
+            base::call_memcpy(b, dst, val, llsz, llalign as u32);
         } else if let Some(ty) = self.cast {
-            let store = Store(bcx, val, PointerCast(bcx, dst, ty.ptr_to()));
-            let llalign = llalign_of_min(bcx.ccx(), self.ty);
-            if !bcx.unreachable.get() {
-                unsafe {
-                    llvm::LLVMSetAlignment(store, llalign);
-                }
+            let cast_dst = b.pointercast(dst, ty.ptr_to());
+            let store = b.store(val, cast_dst);
+            let llalign = llalign_of_min(b.ccx, self.ty);
+            unsafe {
+                llvm::LLVMSetAlignment(store, llalign);
             }
         } else {
-            if self.original_ty == Type::i1(bcx.ccx()) {
-                val = ZExt(bcx, val, Type::i8(bcx.ccx()));
+            if self.original_ty == Type::i1(b.ccx) {
+                val = b.zext(val, Type::i8(b.ccx));
             }
-            Store(bcx, val, dst);
+            b.store(val, dst);
         }
     }
 
@@ -178,7 +178,9 @@ pub fn store_fn_arg(&self, bcx: Block, idx: &mut usize, dst: ValueRef) {
         }
         let val = llvm::get_param(bcx.fcx.llfn, *idx as c_uint);
         *idx += 1;
-        self.store(bcx, val, dst);
+        if !bcx.unreachable.get() {
+            self.store(&B(bcx), val, dst);
+        }
     }
 }
 
index eea53eabec6a4089154ba8b615e33d5b37f56e40..8e1ea73566954fa85d723f2cb34a5328a0bad732 100644 (file)
@@ -1096,29 +1096,29 @@ pub fn trans_unwind_resume(bcx: Block, lpval: ValueRef) {
     }
 }
 
-
-pub fn call_memcpy(cx: Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) {
+pub fn call_memcpy<'bcx, 'tcx>(b: &Builder<'bcx, 'tcx>,
+                               dst: ValueRef,
+                               src: ValueRef,
+                               n_bytes: ValueRef,
+                               align: u32) {
     let _icx = push_ctxt("call_memcpy");
-    let ccx = cx.ccx();
+    let ccx = b.ccx;
     let ptr_width = &ccx.sess().target.target.target_pointer_width[..];
     let key = format!("llvm.memcpy.p0i8.p0i8.i{}", ptr_width);
     let memcpy = ccx.get_intrinsic(&key);
-    let src_ptr = PointerCast(cx, src, Type::i8p(ccx));
-    let dst_ptr = PointerCast(cx, dst, Type::i8p(ccx));
-    let size = IntCast(cx, n_bytes, ccx.int_type());
+    let src_ptr = b.pointercast(src, Type::i8p(ccx));
+    let dst_ptr = b.pointercast(dst, Type::i8p(ccx));
+    let size = b.intcast(n_bytes, ccx.int_type());
     let align = C_i32(ccx, align as i32);
     let volatile = C_bool(ccx, false);
-    Call(cx,
-         memcpy,
-         &[dst_ptr, src_ptr, size, align, volatile],
-         DebugLoc::None);
+    b.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
 }
 
 pub fn memcpy_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, dst: ValueRef, src: ValueRef, t: Ty<'tcx>) {
     let _icx = push_ctxt("memcpy_ty");
     let ccx = bcx.ccx();
 
-    if type_is_zero_size(ccx, t) {
+    if type_is_zero_size(ccx, t) || bcx.unreachable.get() {
         return;
     }
 
@@ -1126,7 +1126,7 @@ pub fn memcpy_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, dst: ValueRef, src: ValueRe
         let llty = type_of::type_of(ccx, t);
         let llsz = llsize_of(ccx, llty);
         let llalign = type_of::align_of(ccx, t);
-        call_memcpy(bcx, dst, src, llsz, llalign as u32);
+        call_memcpy(&B(bcx), dst, src, llsz, llalign as u32);
     } else if common::type_is_fat_ptr(bcx.tcx(), t) {
         let (data, extra) = load_fat_ptr(bcx, src, t);
         store_fat_ptr(bcx, data, extra, dst, t);
@@ -1746,7 +1746,7 @@ pub fn build_return_block(&self, ret_cx: Block<'blk, 'tcx>,
                 assert_eq!(cast_ty, None);
                 let llsz = llsize_of(self.ccx, self.fn_ty.ret.ty);
                 let llalign = llalign_of_min(self.ccx, self.fn_ty.ret.ty);
-                call_memcpy(ret_cx, get_param(self.llfn, 0),
+                call_memcpy(&B(ret_cx), get_param(self.llfn, 0),
                             retslot, llsz, llalign as u32);
                 RetVoid(ret_cx, ret_debug_location)
             }
index 578d495e9b8e67bcc5a4467386199dfc2ab560a3..fcf2f4705ca18f9aa7b87a3d5744b36a0f5d6efa 100644 (file)
@@ -739,8 +739,11 @@ fn trans_call_inner<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
             let llrust_align = llalign_of_min(ccx, llrust_ret_ty);
             let llalign = cmp::min(llforeign_align, llrust_align);
             debug!("llrust_size={}", llrust_size);
-            base::call_memcpy(bcx, llretptr_i8, llscratch_i8,
-                              C_uint(ccx, llrust_size), llalign as u32);
+
+            if !bcx.unreachable.get() {
+                base::call_memcpy(&B(bcx), llretptr_i8, llscratch_i8,
+                                  C_uint(ccx, llrust_size), llalign as u32);
+            }
             base::call_lifetime_end(bcx, llscratch);
         } else if let Some(llretslot) = opt_llretslot {
             base::store_ty(bcx, llret, llretslot, output.unwrap());
index 6c48525abe0652ce188600708d37f436019d4f1e..7a0ca86f5a27087656df902e288232868287dbbd 100644 (file)
@@ -174,11 +174,9 @@ fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                             let bytes = s.len();
                             let llbytes = C_uint(bcx.ccx(), bytes);
                             let llcstr = C_cstr(bcx.ccx(), (*s).clone(), false);
-                            base::call_memcpy(bcx,
-                                              lldest,
-                                              llcstr,
-                                              llbytes,
-                                              1);
+                            if !bcx.unreachable.get() {
+                                base::call_memcpy(&B(bcx), lldest, llcstr, llbytes, 1);
+                            }
                             return bcx;
                         }
                     }