trans: Take a &Builder in call_memcpy, like call_memset.

This commit is contained in:
Eduard Burtescu 2016-03-08 14:29:46 +02:00
parent b63a5eed6e
commit 38638d37f7
4 changed files with 38 additions and 35 deletions

View 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 @@ impl ArgType {
/// 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 @@ impl ArgType {
}
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);
}
}
}

View 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 @@ impl<'blk, 'tcx> FunctionContext<'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)
}

View 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());

View 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;
}
}