提交 727a5d54 编写于 作者: B Björn Steinbrink

Prefer alloc_ty() instead of alloca() where possible

上级 95337a29
......@@ -1196,8 +1196,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let unsized_ty = def.struct_variant().fields.last().map(|field| {
monomorphize::field_ty(bcx.tcx(), substs, field)
}).unwrap();
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
let scratch = alloca(bcx, llty, "__struct_field_fat_ptr");
let scratch = alloc_ty(bcx, unsized_ty, "__struct_field_fat_ptr");
let data = adt::trans_field_ptr(bcx, &*repr, struct_val, 0, arg_count);
let len = Load(bcx, expr::get_meta(bcx, val.val));
Store(bcx, data, expr::get_dataptr(bcx, scratch));
......
......@@ -1020,8 +1020,7 @@ pub fn alloc_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, name: &str) ->
let ccx = bcx.ccx();
let ty = type_of::type_of(ccx, t);
assert!(!t.has_param_types());
let val = alloca(bcx, ty, name);
return val;
alloca(bcx, ty, name)
}
pub fn alloca(cx: Block, ty: Type, name: &str) -> ValueRef {
......
......@@ -101,7 +101,6 @@
use trans::cleanup::{CleanupMethods, DropHintDatum, DropHintMethods};
use trans::expr;
use trans::tvec;
use trans::type_of;
use middle::ty::Ty;
use std::fmt;
......@@ -302,8 +301,7 @@ pub fn lvalue_scratch_datum<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
-> DatumBlock<'blk, 'tcx, Lvalue> where
F: FnOnce(A, Block<'blk, 'tcx>, ValueRef) -> Block<'blk, 'tcx>,
{
let llty = type_of::type_of(bcx.ccx(), ty);
let scratch = alloca(bcx, llty, name);
let scratch = alloc_ty(bcx, ty, name);
// Subtle. Populate the scratch memory *before* scheduling cleanup.
call_lifetime_start(bcx, scratch);
......@@ -323,8 +321,7 @@ pub fn rvalue_scratch_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
ty: Ty<'tcx>,
name: &str)
-> Datum<'tcx, Rvalue> {
let llty = type_of::type_of(bcx.ccx(), ty);
let scratch = alloca(bcx, llty, name);
let scratch = alloc_ty(bcx, ty, name);
call_lifetime_start(bcx, scratch);
Datum::new(scratch, ty, Rvalue::new(ByRef))
}
......
......@@ -246,8 +246,7 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Maybe just get the value directly, instead of loading it?
immediate_rvalue(load_ty(bcx, global, const_ty), const_ty)
} else {
let llty = type_of::type_of(bcx.ccx(), const_ty);
let scratch = alloca(bcx, llty, "const");
let scratch = alloc_ty(bcx, const_ty, "const");
call_lifetime_start(bcx, scratch);
let lldest = if !const_ty.is_structural() {
// Cast pointer to slot, because constants have different types.
......@@ -410,9 +409,8 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
datum.to_rvalue_datum(bcx, "__coerce_source"));
let target = bcx.monomorphize(&target);
let llty = type_of::type_of(bcx.ccx(), target);
let scratch = alloca(bcx, llty, "__coerce_target");
let scratch = alloc_ty(bcx, target, "__coerce_target");
call_lifetime_start(bcx, scratch);
let target_datum = Datum::new(scratch, target,
Rvalue::new(ByRef));
......
......@@ -296,10 +296,7 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Ensure that we always have the Rust value indirectly,
// because it makes bitcasting easier.
if !rust_indirect {
let scratch =
base::alloca(bcx,
type_of::type_of(ccx, passed_arg_tys[i]),
"__arg");
let scratch = base::alloc_ty(bcx, passed_arg_tys[i], "__arg");
if type_is_fat_ptr(ccx.tcx(), passed_arg_tys[i]) {
Store(bcx, llargs_rust[i + offset], expr::get_dataptr(bcx, scratch));
Store(bcx, llargs_rust[i + offset + 1], expr::get_meta(bcx, scratch));
......
......@@ -187,7 +187,7 @@ pub fn drop_ty_immediate<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
skip_dtor: bool)
-> Block<'blk, 'tcx> {
let _icx = push_ctxt("drop_ty_immediate");
let vp = alloca(bcx, type_of(bcx.ccx(), t), "");
let vp = alloc_ty(bcx, t, "");
call_lifetime_start(bcx, vp);
store_ty(bcx, v, vp, t);
let bcx = drop_ty_core(bcx, vp, t, debug_loc, skip_dtor, None);
......
......@@ -106,11 +106,10 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
debug!(" vt={}, count={}", vt.to_string(ccx), count);
let fixed_ty = bcx.tcx().mk_array(vt.unit_ty, count);
let llfixed_ty = type_of::type_of(bcx.ccx(), fixed_ty);
// Always create an alloca even if zero-sized, to preserve
// the non-null invariant of the inner slice ptr
let llfixed = base::alloca(bcx, llfixed_ty, "");
let llfixed = base::alloc_ty(bcx, fixed_ty, "");
call_lifetime_start(bcx, llfixed);
if count > 0 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册