提交 591b2802 编写于 作者: M Michael Sullivan

Make trans only generate calls to the _dyn malloc upcalls, so we can get rid of the non dyn ones.

上级 4c0d41cf
......@@ -156,6 +156,7 @@ exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) {
return (uintptr_t)header;
}
// FIXME: remove after snapshot (6/13/12)
struct s_exchange_malloc_args {
uintptr_t retval;
type_desc *td;
......@@ -238,6 +239,7 @@ shared_malloc(rust_task *task, type_desc *td, uintptr_t size) {
return (uintptr_t)box;
}
// FIXME: remove after snapshot (6/13/12)
struct s_malloc_args {
uintptr_t retval;
type_desc *td;
......
......@@ -10,10 +10,8 @@
type upcalls =
{_fail: ValueRef,
trace: ValueRef,
malloc: ValueRef,
malloc_dyn: ValueRef,
free: ValueRef,
exchange_malloc: ValueRef,
exchange_malloc_dyn: ValueRef,
exchange_free: ValueRef,
validate_box: ValueRef,
......@@ -57,17 +55,12 @@ fn nothrow(f: ValueRef) -> ValueRef {
trace: dv("trace", [T_ptr(T_i8()),
T_ptr(T_i8()),
int_t]),
malloc:
nothrow(d("malloc", [T_ptr(tydesc_type)],
malloc_dyn:
nothrow(d("malloc_dyn",
[T_ptr(tydesc_type), int_t],
T_ptr(T_i8()))),
free:
nothrow(dv("free", [T_ptr(T_i8())])),
exchange_malloc:
nothrow(d("exchange_malloc", [T_ptr(tydesc_type)],
T_ptr(T_i8()))),
exchange_malloc_dyn:
nothrow(d("exchange_malloc_dyn",
[T_ptr(tydesc_type), int_t],
......
......@@ -348,17 +348,17 @@ fn opaque_box_body(bcx: block,
PointerCast(bcx, bodyptr, T_ptr(type_of(ccx, body_t)))
}
// malloc_raw: expects an unboxed type and returns a pointer to
// enough space for a box of that type. This includes a rust_opaque_box
// header.
fn malloc_raw(bcx: block, t: ty::t, heap: heap) -> ValueRef {
// malloc_raw_dyn: allocates a box to contain a given type, but with a
// potentially dynamic size.
fn malloc_raw_dyn(bcx: block, t: ty::t, heap: heap,
size: ValueRef) -> ValueRef {
let _icx = bcx.insn_ctxt("malloc_raw");
let ccx = bcx.ccx();
let (mk_fn, upcall) = alt heap {
heap_shared { (ty::mk_imm_box, ccx.upcalls.malloc) }
heap_shared { (ty::mk_imm_box, ccx.upcalls.malloc_dyn) }
heap_exchange {
(ty::mk_imm_uniq, ccx.upcalls.exchange_malloc )
(ty::mk_imm_uniq, ccx.upcalls.exchange_malloc_dyn )
}
};
......@@ -372,52 +372,40 @@ fn malloc_raw(bcx: block, t: ty::t, heap: heap) -> ValueRef {
lazily_emit_all_tydesc_glue(ccx, copy static_ti);
// Allocate space:
let rval = Call(bcx, upcall, [lltydesc]);
let rval = Call(bcx, upcall, [lltydesc, size]);
ret PointerCast(bcx, rval, llty);
}
// malloc_general: usefully wraps malloc_raw; allocates a box,
// malloc_raw: expects an unboxed type and returns a pointer to
// enough space for a box of that type. This includes a rust_opaque_box
// header.
fn malloc_raw(bcx: block, t: ty::t, heap: heap) -> ValueRef {
malloc_raw_dyn(bcx, t, heap, llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
}
// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a box,
// and pulls out the body
fn malloc_general(bcx: block, t: ty::t, heap: heap) ->
fn malloc_general_dyn(bcx: block, t: ty::t, heap: heap, size: ValueRef) ->
{box: ValueRef, body: ValueRef} {
let _icx = bcx.insn_ctxt("malloc_general");
let box = malloc_raw(bcx, t, heap);
let box = malloc_raw_dyn(bcx, t, heap, size);
let non_gc_box = non_gc_box_cast(bcx, box);
let body = GEPi(bcx, non_gc_box, [0u, abi::box_field_body]);
ret {box: box, body: body};
}
fn malloc_boxed(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
malloc_general(bcx, t, heap_shared)
malloc_general_dyn(bcx, t, heap_shared,
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
}
fn malloc_unique(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
malloc_general(bcx, t, heap_exchange)
}
fn malloc_unique_dyn_raw(bcx: block, t: ty::t, size: ValueRef) -> ValueRef {
let _icx = bcx.insn_ctxt("malloc_unique_dyn_raw");
let ccx = bcx.ccx();
// Grab the TypeRef type of box_ptr_ty.
let box_ptr_ty = ty::mk_imm_uniq(ccx.tcx, t);
let llty = type_of(ccx, box_ptr_ty);
// Get the tydesc for the body:
let mut static_ti = none;
let lltydesc = get_tydesc(ccx, t, static_ti);
lazily_emit_all_tydesc_glue(ccx, static_ti);
// Allocate space:
let rval = Call(bcx, ccx.upcalls.exchange_malloc_dyn, [lltydesc, size]);
ret PointerCast(bcx, rval, llty);
malloc_general_dyn(bcx, t, heap_exchange,
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
}
fn malloc_unique_dyn(bcx: block, t: ty::t, size: ValueRef
) -> {box: ValueRef, body: ValueRef} {
let _icx = bcx.insn_ctxt("malloc_unique_dyn");
let box = malloc_unique_dyn_raw(bcx, t, size);
let body = GEPi(bcx, box, [0u, abi::box_field_body]);
ret {box: box, body: body};
malloc_general_dyn(bcx, t, heap_exchange, size)
}
// Type descriptor and type glue stuff
......
......@@ -553,8 +553,8 @@ fn make_opaque_cbox_take_glue(
let sz = Add(bcx, sz, shape::llsize_of(ccx, T_box_header(ccx)));
// Allocate memory, update original ptr, and copy existing data
let malloc = ccx.upcalls.exchange_malloc;
let cbox_out = Call(bcx, malloc, [tydesc]);
let malloc = ccx.upcalls.exchange_malloc_dyn;
let cbox_out = Call(bcx, malloc, [tydesc, sz]);
let cbox_out = PointerCast(bcx, cbox_out, llopaquecboxty);
call_memmove(bcx, cbox_out, cbox_in, sz);
Store(bcx, cbox_out, cboxptr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册