1
Fork 0

Remove remaining evec support from trans

This commit is contained in:
Marijn Haverbeke 2011-09-02 15:32:37 +02:00
parent 9c173f17c0
commit a0e2809f54
5 changed files with 8 additions and 141 deletions

View file

@ -15,10 +15,8 @@ import middle::trans_common::T_nil;
import middle::trans_common::T_opaque_chan_ptr;
import middle::trans_common::T_opaque_ivec;
import middle::trans_common::T_opaque_port_ptr;
import middle::trans_common::T_opaque_vec_ptr;
import middle::trans_common::T_ptr;
import middle::trans_common::T_size_t;
import middle::trans_common::T_str;
import middle::trans_common::T_void;
import lib::llvm::type_names;
import lib::llvm::llvm::ModuleRef;
@ -37,8 +35,6 @@ type upcalls =
shared_malloc: ValueRef,
shared_free: ValueRef,
mark: ValueRef,
new_str: ValueRef,
evec_append: ValueRef,
get_type_desc: ValueRef,
ivec_grow: ValueRef,
ivec_push: ValueRef,
@ -82,12 +78,6 @@ fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef,
T_ptr(T_i8())),
shared_free: dv(~"shared_free", [T_ptr(T_i8())]),
mark: d(~"mark", [T_ptr(T_i8())], T_int()),
new_str: d(~"new_str", [T_ptr(T_i8()), T_size_t()], T_ptr(T_str())),
evec_append:
d(~"evec_append",
[T_ptr(tydesc_type), T_ptr(tydesc_type),
T_ptr(T_opaque_vec_ptr()), T_opaque_vec_ptr(), T_bool()],
T_void()),
get_type_desc:
d(~"get_type_desc",
[T_ptr(T_nil()), T_size_t(), T_size_t(), T_size_t(),

View file

@ -55,7 +55,7 @@ const shape_i32: u8 = 6u8;
const shape_i64: u8 = 7u8;
const shape_f32: u8 = 8u8;
const shape_f64: u8 = 9u8;
const shape_evec: u8 = 10u8;
// (10 is currently unused, was evec)
const shape_ivec: u8 = 11u8;
const shape_tag: u8 = 12u8;
const shape_box: u8 = 13u8;

View file

@ -2334,39 +2334,6 @@ fn trans_compare(cx: &@block_ctxt, op: ast::binop, lhs: ValueRef,
}
}
fn trans_evec_append(cx: &@block_ctxt, t: ty::t, lhs: ValueRef,
rhs: ValueRef) -> result {
let elt_ty = ty::sequence_element_type(bcx_tcx(cx), t);
let skip_null = C_bool(false);
let bcx = cx;
let ti = none::<@tydesc_info>;
let llvec_tydesc = get_tydesc(bcx, t, false, tps_normal, ti).result;
bcx = llvec_tydesc.bcx;
ti = none::<@tydesc_info>;
let llelt_tydesc = get_tydesc(bcx, elt_ty, false, tps_normal, ti).result;
lazily_emit_tydesc_glue(cx, abi::tydesc_field_take_glue, ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_drop_glue, ti);
lazily_emit_tydesc_glue(cx, abi::tydesc_field_free_glue, ti);
bcx = llelt_tydesc.bcx;
let dst = PointerCast(bcx, lhs, T_ptr(T_opaque_vec_ptr()));
let src = PointerCast(bcx, rhs, T_opaque_vec_ptr());
ret rslt(bcx,
Call(bcx, bcx_ccx(cx).upcalls.evec_append,
[cx.fcx.lltaskptr, llvec_tydesc.val,
llelt_tydesc.val, dst, src, skip_null]));
}
fn trans_evec_add(cx: &@block_ctxt, t: ty::t, lhs: ValueRef, rhs: ValueRef)
-> result {
let r = alloc_ty(cx, t);
let tmp = r.val;
let bcx = copy_val(r.bcx, INIT, tmp, lhs, t);
let bcx = trans_evec_append(bcx, t, tmp, rhs).bcx;
tmp = load_if_immediate(bcx, tmp, t);
add_clean_temp(cx, tmp, t);
ret rslt(bcx, tmp);
}
// Important to get types for both lhs and rhs, because one might be _|_
// and the other not.
fn trans_eager_binop(cx: &@block_ctxt, op: ast::binop, lhs: ValueRef,
@ -2390,10 +2357,7 @@ fn trans_eager_binop(cx: &@block_ctxt, op: ast::binop, lhs: ValueRef,
alt op {
ast::add. {
if ty::type_is_sequence(bcx_tcx(cx), intype) {
if ty::sequence_is_interior(bcx_tcx(cx), intype) {
ret ivec::trans_add(cx, intype, lhs, rhs);
}
ret trans_evec_add(cx, intype, lhs, rhs);
ret ivec::trans_add(cx, intype, lhs, rhs);
}
if is_float {
ret rslt(cx, FAdd(cx, lhs, rhs));
@ -3185,8 +3149,6 @@ fn trans_index(cx: &@block_ctxt, sp: &span, base: &@ast::expr,
let base_ty = ty::expr_ty(bcx_tcx(cx), base);
let exp = trans_expr(cx, base);
let lv = autoderef(exp.bcx, exp.val, base_ty);
let base_ty_no_boxes = lv.ty;
let is_interior = ty::sequence_is_interior(bcx_tcx(cx), base_ty_no_boxes);
let ix = trans_expr(lv.bcx, idx);
let v = lv.val;
let bcx = ix.bcx;
@ -3206,20 +3168,8 @@ fn trans_index(cx: &@block_ctxt, sp: &span, base: &@ast::expr,
maybe_name_value(bcx_ccx(cx), unit_sz.val, ~"unit_sz");
let scaled_ix = Mul(bcx, ix_val, unit_sz.val);
maybe_name_value(bcx_ccx(cx), scaled_ix, ~"scaled_ix");
let interior_len_and_data;
if is_interior {
let len = ivec::get_fill(bcx, v);
let data = ivec::get_dataptr(bcx, v, type_of_or_i8(bcx, unit_ty));
interior_len_and_data = some({len: len, data: data});
} else { interior_len_and_data = none; }
let lim;
alt interior_len_and_data {
some(lad) { lim = lad.len; }
none. {
lim = GEP(bcx, v, [C_int(0), C_int(abi::vec_elt_fill)]);
lim = Load(bcx, lim);
}
}
let lim = ivec::get_fill(bcx, v);
let body = ivec::get_dataptr(bcx, v, type_of_or_i8(bcx, unit_ty));
let bounds_check = ICmp(bcx, lib::llvm::LLVMIntULT, scaled_ix, lim);
let fail_cx = new_sub_block_ctxt(bcx, ~"fail");
let next_cx = new_sub_block_ctxt(bcx, ~"next");
@ -3227,15 +3177,6 @@ fn trans_index(cx: &@block_ctxt, sp: &span, base: &@ast::expr,
// fail: bad bounds check.
trans_fail(fail_cx, some::<span>(sp), ~"bounds check");
let body;
alt interior_len_and_data {
some(lad) { body = lad.data; }
none. {
body =
GEP(next_cx, v,
[C_int(0), C_int(abi::vec_elt_data), C_int(0)]);
}
}
let elt;
if ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty) {
body = PointerCast(next_cx, body, T_ptr(T_i8()));
@ -3683,18 +3624,7 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef,
// to have type lldestty0 (the callee's expected type).
val = llvm::LLVMGetUndef(lldestty0);
} else if arg.mode == ty::mo_val {
// Eliding take/drop for appending of external vectors currently
// corrupts memory. I can't figure out why, and external vectors
// are on the way out anyway, so this simply turns off the
// optimization for that case.
let is_ext_vec_plus = alt e.node {
ast::expr_binary(_, _, _) {
ty::type_is_sequence(ccx.tcx, e_ty) &&
!ty::sequence_is_interior(ccx.tcx, e_ty)
}
_ { false }
};
if !lv.is_mem && !is_ext_vec_plus {
if !lv.is_mem {
// Do nothing for temporaries, just give them to callee
} else if type_is_structural_or_param(ccx.tcx, e_ty) {
let dst = alloc_ty(bcx, e_ty);
@ -3706,12 +3636,9 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef,
let arg_copy = do_spill(bcx, Load(bcx, val));
bcx = take_ty(bcx, arg_copy, e_ty);
val = Load(bcx, arg_copy);
} else if lv.is_mem {
} else {
bcx = take_ty(bcx, val, e_ty);
val = load_if_immediate(bcx, val, e_ty);
} else if is_ext_vec_plus {
let spilled = do_spill(bcx, val);
bcx = take_ty(bcx, spilled, e_ty);
}
add_clean_temp(bcx, val, e_ty);
}
@ -4144,12 +4071,8 @@ fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) ->
if ty::type_is_sequence(tcx, t) {
alt op {
ast::add. {
if ty::sequence_is_interior(tcx, t) {
ret ivec::trans_append(rhs_res.bcx, t, lhs_res.res.val,
rhs_res.val);
}
ret trans_evec_append(rhs_res.bcx, t, lhs_res.res.val,
rhs_res.val);
ret ivec::trans_append(rhs_res.bcx, t, lhs_res.res.val,
rhs_res.val);
}
_ { }
}

View file

@ -639,18 +639,6 @@ fn T_tydesc(taskptr_type: TypeRef) -> TypeRef {
fn T_array(t: TypeRef, n: uint) -> TypeRef { ret llvm::LLVMArrayType(t, n); }
fn T_evec(t: TypeRef) -> TypeRef {
ret T_struct([T_int(), // Refcount
T_int(), // Alloc
T_int(), // Fill
T_int(), // Pad
// Body elements
T_array(t, 0u)]);
}
fn T_opaque_vec_ptr() -> TypeRef { ret T_ptr(T_evec(T_int())); }
// Interior vector.
//
@ -666,8 +654,6 @@ fn T_opaque_ivec() -> TypeRef {
ret T_ivec(T_i8());
}
fn T_str() -> TypeRef { ret T_evec(T_i8()); }
fn T_box(t: TypeRef) -> TypeRef { ret T_struct([T_int(), t]); }
fn T_port(_t: TypeRef) -> TypeRef {
@ -812,29 +798,6 @@ fn C_cstr(cx: &@crate_ctxt, s: &istr) -> ValueRef {
ret g;
}
// A rust boxed-and-length-annotated string.
fn C_str(cx: &@crate_ctxt, s: &istr) -> ValueRef {
let len =
str::byte_len(s); // 'alloc'
// 'fill'
// 'pad'
let cstr = str::as_buf(s, { |buf|
llvm::LLVMConstString(buf, len, False)
});
let box =
C_struct([C_int(abi::const_refcount as int), C_int(len + 1u as int),
C_int(len + 1u as int), C_int(0), cstr]);
let g = str::as_buf(cx.names.next(~"str"), { |buf|
llvm::LLVMAddGlobal(cx.llmod, val_ty(box), buf)
});
llvm::LLVMSetInitializer(g, box);
llvm::LLVMSetGlobalConstant(g, True);
llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage as llvm::Linkage);
ret llvm::LLVMConstPointerCast(g, T_ptr(T_str()));
}
// Returns a Plain Old LLVM String:
fn C_postr(s: &istr) -> ValueRef {
ret str::as_buf(s, { |buf|

View file

@ -97,7 +97,6 @@ export rename;
export ret_ty_of_fn;
export ret_ty_of_fn_ty;
export sequence_element_type;
export sequence_is_interior;
export struct;
export sort_methods;
export stmt_node_id;
@ -833,14 +832,6 @@ fn type_is_str(cx: &ctxt, ty: t) -> bool {
}
}
fn sequence_is_interior(cx: &ctxt, ty: t) -> bool {
alt struct(cx, ty) {
ty::ty_vec(_) { ret true; }
ty::ty_istr. { ret true; }
_ { cx.sess.bug(~"sequence_is_interior called on non-sequence type"); }
}
}
fn sequence_element_type(cx: &ctxt, ty: t) -> t {
alt struct(cx, ty) {
ty_istr. { ret mk_mach(cx, ast::ty_u8); }