mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Simplify a bunch of trans functions to not need the rust type. Remove some PointerCasts.
This commit is contained in:
parent
ccf4e8cf9a
commit
35dd717352
@ -462,8 +462,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef],
|
|||||||
// Unbox in case of a box field
|
// Unbox in case of a box field
|
||||||
if any_box_pat(m, col) {
|
if any_box_pat(m, col) {
|
||||||
let box = Load(bcx, val);
|
let box = Load(bcx, val);
|
||||||
let box_ty = node_id_type(bcx, pat_id);
|
let box_no_addrspace = non_gc_box_cast(bcx, box);
|
||||||
let box_no_addrspace = non_gc_box_cast(bcx, box, box_ty);
|
|
||||||
let unboxed = GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]);
|
let unboxed = GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]);
|
||||||
compile_submatch(bcx, enter_box(dm, m, col, val), [unboxed]
|
compile_submatch(bcx, enter_box(dm, m, col, val), [unboxed]
|
||||||
+ vals_left, chk, exits);
|
+ vals_left, chk, exits);
|
||||||
@ -472,8 +471,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef],
|
|||||||
|
|
||||||
if any_uniq_pat(m, col) {
|
if any_uniq_pat(m, col) {
|
||||||
let box = Load(bcx, val);
|
let box = Load(bcx, val);
|
||||||
let box_ty = node_id_type(bcx, pat_id);
|
let box_no_addrspace = non_gc_box_cast(bcx, box);
|
||||||
let box_no_addrspace = non_gc_box_cast(bcx, box, box_ty);
|
|
||||||
let unboxed = GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]);
|
let unboxed = GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]);
|
||||||
compile_submatch(bcx, enter_uniq(dm, m, col, val),
|
compile_submatch(bcx, enter_uniq(dm, m, col, val),
|
||||||
[unboxed] + vals_left, chk, exits);
|
[unboxed] + vals_left, chk, exits);
|
||||||
|
@ -381,10 +381,8 @@ fn malloc_raw(bcx: block, t: ty::t, heap: heap) -> ValueRef {
|
|||||||
fn malloc_general(bcx: block, t: ty::t, heap: heap) ->
|
fn malloc_general(bcx: block, t: ty::t, heap: heap) ->
|
||||||
{box: ValueRef, body: ValueRef} {
|
{box: ValueRef, body: ValueRef} {
|
||||||
let _icx = bcx.insn_ctxt("malloc_general");
|
let _icx = bcx.insn_ctxt("malloc_general");
|
||||||
let mk_ty = alt heap { heap_shared { ty::mk_imm_box }
|
|
||||||
heap_exchange { ty::mk_imm_uniq } };
|
|
||||||
let box = malloc_raw(bcx, t, heap);
|
let box = malloc_raw(bcx, t, heap);
|
||||||
let non_gc_box = non_gc_box_cast(bcx, box, mk_ty(bcx.tcx(), t));
|
let non_gc_box = non_gc_box_cast(bcx, box);
|
||||||
let body = GEPi(bcx, non_gc_box, [0u, abi::box_field_body]);
|
let body = GEPi(bcx, non_gc_box, [0u, abi::box_field_body]);
|
||||||
ret {box: box, body: body};
|
ret {box: box, body: body};
|
||||||
}
|
}
|
||||||
@ -2682,11 +2680,11 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
|
|||||||
let t = expr_ty(cx, base);
|
let t = expr_ty(cx, base);
|
||||||
let val = alt check ty::get(t).struct {
|
let val = alt check ty::get(t).struct {
|
||||||
ty::ty_box(_) {
|
ty::ty_box(_) {
|
||||||
let non_gc_val = non_gc_box_cast(sub.bcx, sub.val, t);
|
let non_gc_val = non_gc_box_cast(sub.bcx, sub.val);
|
||||||
GEPi(sub.bcx, non_gc_val, [0u, abi::box_field_body])
|
GEPi(sub.bcx, non_gc_val, [0u, abi::box_field_body])
|
||||||
}
|
}
|
||||||
ty::ty_uniq(_) {
|
ty::ty_uniq(_) {
|
||||||
let non_gc_val = non_gc_box_cast(sub.bcx, sub.val, t);
|
let non_gc_val = non_gc_box_cast(sub.bcx, sub.val);
|
||||||
GEPi(sub.bcx, non_gc_val, [0u, abi::box_field_body])
|
GEPi(sub.bcx, non_gc_val, [0u, abi::box_field_body])
|
||||||
}
|
}
|
||||||
ty::ty_res(_, _, _) {
|
ty::ty_res(_, _, _) {
|
||||||
@ -2714,10 +2712,11 @@ Before taking a pointer to the inside of a box it should be cast into address
|
|||||||
space 0. Otherwise the resulting (non-box) pointer will be in the wrong
|
space 0. Otherwise the resulting (non-box) pointer will be in the wrong
|
||||||
address space and thus be the wrong type.
|
address space and thus be the wrong type.
|
||||||
"]
|
"]
|
||||||
fn non_gc_box_cast(cx: block, val: ValueRef, t: ty::t) -> ValueRef {
|
fn non_gc_box_cast(cx: block, val: ValueRef) -> ValueRef {
|
||||||
#debug("non_gc_box_cast");
|
#debug("non_gc_box_cast");
|
||||||
add_comment(cx, "non_gc_box_cast");
|
add_comment(cx, "non_gc_box_cast");
|
||||||
let non_gc_t = type_of_non_gc_box(cx.ccx(), t);
|
assert(llvm::LLVMGetPointerAddressSpace(val_ty(val)) as uint == 1u);
|
||||||
|
let non_gc_t = T_ptr(llvm::LLVMGetElementType(val_ty(val)));
|
||||||
PointerCast(cx, val, non_gc_t)
|
PointerCast(cx, val, non_gc_t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3885,11 +3884,8 @@ fn trans_fail_expr(bcx: block, sp_opt: option<span>,
|
|||||||
bcx = expr_res.bcx;
|
bcx = expr_res.bcx;
|
||||||
|
|
||||||
if ty::type_is_str(e_ty) {
|
if ty::type_is_str(e_ty) {
|
||||||
let unit_ty = ty::mk_mach_uint(tcx, ast::ty_u8);
|
let body = tvec::get_bodyptr(bcx, expr_res.val);
|
||||||
let vec_ty = ty::mk_vec(tcx, {ty: unit_ty, mutbl: ast::m_imm});
|
let data = tvec::get_dataptr(bcx, body);
|
||||||
let unit_llty = type_of(ccx, unit_ty);
|
|
||||||
let body = tvec::get_bodyptr(bcx, expr_res.val, vec_ty);
|
|
||||||
let data = tvec::get_dataptr(bcx, body, unit_llty);
|
|
||||||
ret trans_fail_value(bcx, sp_opt, data);
|
ret trans_fail_value(bcx, sp_opt, data);
|
||||||
} else if bcx.unreachable || ty::type_is_bot(e_ty) {
|
} else if bcx.unreachable || ty::type_is_bot(e_ty) {
|
||||||
ret bcx;
|
ret bcx;
|
||||||
|
@ -5,11 +5,12 @@ import back::abi;
|
|||||||
import base::{call_memmove,
|
import base::{call_memmove,
|
||||||
INIT, copy_val, load_if_immediate, get_tydesc,
|
INIT, copy_val, load_if_immediate, get_tydesc,
|
||||||
sub_block, do_spill_noroot,
|
sub_block, do_spill_noroot,
|
||||||
dest, bcx_icx};
|
dest, bcx_icx, non_gc_box_cast};
|
||||||
import syntax::codemap::span;
|
import syntax::codemap::span;
|
||||||
import shape::llsize_of;
|
import shape::llsize_of;
|
||||||
import build::*;
|
import build::*;
|
||||||
import common::*;
|
import common::*;
|
||||||
|
import util::ppaux::ty_to_str;
|
||||||
|
|
||||||
fn get_fill(bcx: block, vptr: ValueRef) -> ValueRef {
|
fn get_fill(bcx: block, vptr: ValueRef) -> ValueRef {
|
||||||
let _icx = bcx.insn_ctxt("tvec::get_fill");
|
let _icx = bcx.insn_ctxt("tvec::get_fill");
|
||||||
@ -22,28 +23,14 @@ fn get_alloc(bcx: block, vptr: ValueRef) -> ValueRef {
|
|||||||
Load(bcx, GEPi(bcx, vptr, [0u, abi::vec_elt_alloc]))
|
Load(bcx, GEPi(bcx, vptr, [0u, abi::vec_elt_alloc]))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_bodyptr(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> ValueRef {
|
fn get_bodyptr(bcx: block, vptr: ValueRef) -> ValueRef {
|
||||||
let ccx = bcx.ccx();
|
non_gc_box_cast(bcx, GEPi(bcx, vptr, [0u, abi::box_field_body]))
|
||||||
alt ty::get(vec_ty).struct {
|
|
||||||
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq)
|
|
||||||
| ty::ty_vec(_) | ty::ty_str {
|
|
||||||
let boxptr = PointerCast(bcx, vptr, T_ptr(T_box_header(ccx)));
|
|
||||||
let bodyptr = GEPi(bcx, boxptr, [1u]);
|
|
||||||
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
|
|
||||||
let llunit_ty = type_of::type_of(ccx, unit_ty);
|
|
||||||
PointerCast(bcx, bodyptr, T_ptr(T_vec(ccx, llunit_ty)))
|
|
||||||
}
|
|
||||||
_ {
|
|
||||||
vptr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_dataptr(bcx: block, vptr: ValueRef, unit_ty: TypeRef)
|
fn get_dataptr(bcx: block, vptr: ValueRef)
|
||||||
-> ValueRef {
|
-> ValueRef {
|
||||||
let _icx = bcx.insn_ctxt("tvec::get_dataptr");
|
let _icx = bcx.insn_ctxt("tvec::get_dataptr");
|
||||||
let ptr = GEPi(bcx, vptr, [0u, abi::vec_elt_elems]);
|
GEPi(bcx, vptr, [0u, abi::vec_elt_elems, 0u])
|
||||||
PointerCast(bcx, ptr, T_ptr(unit_ty))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_add(bcx: block, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
|
fn pointer_add(bcx: block, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
|
||||||
@ -83,7 +70,7 @@ fn alloc_uniq(bcx: block, unit_ty: ty::t, elts: uint) -> result {
|
|||||||
fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> result {
|
fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> result {
|
||||||
let _icx = bcx.insn_ctxt("tvec::duplicate_uniq");
|
let _icx = bcx.insn_ctxt("tvec::duplicate_uniq");
|
||||||
let ccx = bcx.ccx();
|
let ccx = bcx.ccx();
|
||||||
let body_ptr = get_bodyptr(bcx, vptr, vec_ty);
|
let body_ptr = get_bodyptr(bcx, vptr);
|
||||||
let fill = get_fill(bcx, body_ptr);
|
let fill = get_fill(bcx, body_ptr);
|
||||||
let size = Add(bcx, fill, llsize_of(ccx, ccx.opaque_vec_type));
|
let size = Add(bcx, fill, llsize_of(ccx, ccx.opaque_vec_type));
|
||||||
|
|
||||||
@ -159,8 +146,7 @@ fn trans_evec(bcx: block, args: [@ast::expr],
|
|||||||
ast::vstore_uniq {
|
ast::vstore_uniq {
|
||||||
let {bcx, val} = alloc_uniq(bcx, unit_ty, args.len());
|
let {bcx, val} = alloc_uniq(bcx, unit_ty, args.len());
|
||||||
add_clean_free(bcx, val, true);
|
add_clean_free(bcx, val, true);
|
||||||
let body = get_bodyptr(bcx, val, vec_ty);
|
let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val));
|
||||||
let dataptr = get_dataptr(bcx, body, llunitty);
|
|
||||||
{bcx: bcx, val: val, dataptr: dataptr}
|
{bcx: bcx, val: val, dataptr: dataptr}
|
||||||
}
|
}
|
||||||
ast::vstore_box {
|
ast::vstore_box {
|
||||||
@ -241,10 +227,8 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t)
|
|||||||
(base, len)
|
(base, len)
|
||||||
}
|
}
|
||||||
ty::vstore_uniq {
|
ty::vstore_uniq {
|
||||||
let body = tvec::get_bodyptr(cx, v, vec_ty);
|
let body = tvec::get_bodyptr(cx, v);
|
||||||
let base = tvec::get_dataptr(cx, body, llunitty);
|
(tvec::get_dataptr(cx, body), tvec::get_fill(cx, body))
|
||||||
let len = tvec::get_fill(cx, body);
|
|
||||||
(base, len)
|
|
||||||
}
|
}
|
||||||
ty::vstore_box {
|
ty::vstore_box {
|
||||||
cx.ccx().sess.unimpl("unhandled tvec::get_base_and_len");
|
cx.ccx().sess.unimpl("unhandled tvec::get_base_and_len");
|
||||||
@ -297,14 +281,11 @@ fn trans_append(bcx: block, vec_ty: ty::t, lhsptr: ValueRef,
|
|||||||
let ccx = bcx.ccx();
|
let ccx = bcx.ccx();
|
||||||
let unit_ty = ty::sequence_element_type(ccx.tcx, vec_ty);
|
let unit_ty = ty::sequence_element_type(ccx.tcx, vec_ty);
|
||||||
let strings = ty::type_is_str(vec_ty);
|
let strings = ty::type_is_str(vec_ty);
|
||||||
let llunitty = type_of::type_of(ccx, unit_ty);
|
|
||||||
|
|
||||||
let lhs = Load(bcx, lhsptr);
|
let lhs = Load(bcx, lhsptr);
|
||||||
let self_append = ICmp(bcx, lib::llvm::IntEQ, lhs, rhs);
|
let self_append = ICmp(bcx, lib::llvm::IntEQ, lhs, rhs);
|
||||||
let lbody = get_bodyptr(bcx, lhs, vec_ty);
|
let lfill = get_fill(bcx, get_bodyptr(bcx, lhs));
|
||||||
let rbody = get_bodyptr(bcx, rhs, vec_ty);
|
let rfill = get_fill(bcx, get_bodyptr(bcx, rhs));
|
||||||
let lfill = get_fill(bcx, lbody);
|
|
||||||
let rfill = get_fill(bcx, rbody);
|
|
||||||
let mut new_fill = Add(bcx, lfill, rfill);
|
let mut new_fill = Add(bcx, lfill, rfill);
|
||||||
if strings { new_fill = Sub(bcx, new_fill, C_int(ccx, 1)); }
|
if strings { new_fill = Sub(bcx, new_fill, C_int(ccx, 1)); }
|
||||||
let opaque_lhs = PointerCast(bcx, lhsptr,
|
let opaque_lhs = PointerCast(bcx, lhsptr,
|
||||||
@ -315,9 +296,9 @@ fn trans_append(bcx: block, vec_ty: ty::t, lhsptr: ValueRef,
|
|||||||
let lhs = Load(bcx, lhsptr);
|
let lhs = Load(bcx, lhsptr);
|
||||||
let rhs = Select(bcx, self_append, lhs, rhs);
|
let rhs = Select(bcx, self_append, lhs, rhs);
|
||||||
|
|
||||||
let lbody = get_bodyptr(bcx, lhs, vec_ty);
|
let lbody = get_bodyptr(bcx, lhs);
|
||||||
|
|
||||||
let lhs_data = get_dataptr(bcx, lbody, llunitty);
|
let lhs_data = get_dataptr(bcx, lbody);
|
||||||
let mut lhs_off = lfill;
|
let mut lhs_off = lfill;
|
||||||
if strings { lhs_off = Sub(bcx, lhs_off, C_int(ccx, 1)); }
|
if strings { lhs_off = Sub(bcx, lhs_off, C_int(ccx, 1)); }
|
||||||
let write_ptr = pointer_add(bcx, lhs_data, lhs_off);
|
let write_ptr = pointer_add(bcx, lhs_data, lhs_off);
|
||||||
@ -342,7 +323,7 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
|
|||||||
let scratch = base::alloca(bcx, elt_llty);
|
let scratch = base::alloca(bcx, elt_llty);
|
||||||
for vec::each(vals) {|val|
|
for vec::each(vals) {|val|
|
||||||
bcx = base::trans_expr_save_in(bcx, val, scratch);
|
bcx = base::trans_expr_save_in(bcx, val, scratch);
|
||||||
let vptr = get_bodyptr(bcx, Load(bcx, vptrptr), vec_ty);
|
let vptr = get_bodyptr(bcx, Load(bcx, vptrptr));
|
||||||
let old_fill = get_fill(bcx, vptr);
|
let old_fill = get_fill(bcx, vptr);
|
||||||
let new_fill = Add(bcx, old_fill, elt_sz);
|
let new_fill = Add(bcx, old_fill, elt_sz);
|
||||||
let do_grow = ICmp(bcx, lib::llvm::IntUGT, new_fill,
|
let do_grow = ICmp(bcx, lib::llvm::IntUGT, new_fill,
|
||||||
@ -353,9 +334,9 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
|
|||||||
Call(bcx, ccx.upcalls.vec_grow, [pt, new_fill]);
|
Call(bcx, ccx.upcalls.vec_grow, [pt, new_fill]);
|
||||||
bcx
|
bcx
|
||||||
};
|
};
|
||||||
let vptr = get_bodyptr(bcx, Load(bcx, vptrptr), vec_ty);
|
let vptr = get_bodyptr(bcx, Load(bcx, vptrptr));
|
||||||
set_fill(bcx, vptr, new_fill);
|
set_fill(bcx, vptr, new_fill);
|
||||||
let targetptr = pointer_add(bcx, get_dataptr(bcx, vptr, elt_llty),
|
let targetptr = pointer_add(bcx, get_dataptr(bcx, vptr),
|
||||||
old_fill);
|
old_fill);
|
||||||
call_memmove(bcx, targetptr, scratch, elt_sz);
|
call_memmove(bcx, targetptr, scratch, elt_sz);
|
||||||
}
|
}
|
||||||
@ -379,18 +360,15 @@ fn trans_add(bcx: block, vec_ty: ty::t, lhs: ValueRef,
|
|||||||
ret base::store_in_dest(bcx, n, dest);
|
ret base::store_in_dest(bcx, n, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
let lhs_body = get_bodyptr(bcx, lhs, vec_ty);
|
let lhs_fill = get_fill(bcx, get_bodyptr(bcx, lhs));
|
||||||
let rhs_body = get_bodyptr(bcx, rhs, vec_ty);
|
let rhs_fill = get_fill(bcx, get_bodyptr(bcx, rhs));
|
||||||
|
|
||||||
let lhs_fill = get_fill(bcx, lhs_body);
|
|
||||||
let rhs_fill = get_fill(bcx, rhs_body);
|
|
||||||
let new_fill = Add(bcx, lhs_fill, rhs_fill);
|
let new_fill = Add(bcx, lhs_fill, rhs_fill);
|
||||||
let mut {bcx: bcx, val: new_vec_ptr} =
|
let mut {bcx: bcx, val: new_vec_ptr} =
|
||||||
alloc_uniq_raw(bcx, unit_ty, new_fill, new_fill);
|
alloc_uniq_raw(bcx, unit_ty, new_fill, new_fill);
|
||||||
|
|
||||||
let new_vec_body_ptr = get_bodyptr(bcx, new_vec_ptr, vec_ty);
|
let new_vec_body_ptr = get_bodyptr(bcx, new_vec_ptr);
|
||||||
let write_ptr_ptr = do_spill_noroot
|
let write_ptr_ptr = do_spill_noroot
|
||||||
(bcx, get_dataptr(bcx, new_vec_body_ptr, llunitty));
|
(bcx, get_dataptr(bcx, new_vec_body_ptr));
|
||||||
let copy_fn = fn@(bcx: block, addr: ValueRef,
|
let copy_fn = fn@(bcx: block, addr: ValueRef,
|
||||||
_ty: ty::t) -> block {
|
_ty: ty::t) -> block {
|
||||||
let ccx = bcx.ccx();
|
let ccx = bcx.ccx();
|
||||||
@ -443,19 +421,14 @@ fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
|
|||||||
fn iter_vec_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t,
|
fn iter_vec_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t,
|
||||||
fill: ValueRef, f: iter_vec_block) -> block {
|
fill: ValueRef, f: iter_vec_block) -> block {
|
||||||
let _icx = bcx.insn_ctxt("tvec::iter_vec_uniq");
|
let _icx = bcx.insn_ctxt("tvec::iter_vec_uniq");
|
||||||
let ccx = bcx.ccx();
|
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr));
|
||||||
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
|
|
||||||
let llunitty = type_of::type_of(ccx, unit_ty);
|
|
||||||
let body_ptr = get_bodyptr(bcx, vptr, vec_ty);
|
|
||||||
let data_ptr = get_dataptr(bcx, body_ptr, llunitty);
|
|
||||||
iter_vec_raw(bcx, data_ptr, vec_ty, fill, f)
|
iter_vec_raw(bcx, data_ptr, vec_ty, fill, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter_vec(bcx: block, vptr: ValueRef, vec_ty: ty::t,
|
fn iter_vec(bcx: block, vptr: ValueRef, vec_ty: ty::t,
|
||||||
f: iter_vec_block) -> block {
|
f: iter_vec_block) -> block {
|
||||||
let _icx = bcx.insn_ctxt("tvec::iter_vec");
|
let _icx = bcx.insn_ctxt("tvec::iter_vec");
|
||||||
let body_ptr = get_bodyptr(bcx, vptr, vec_ty);
|
let fill = get_fill(bcx, get_bodyptr(bcx, vptr));
|
||||||
let fill = get_fill(bcx, body_ptr);
|
|
||||||
ret iter_vec_uniq(bcx, vptr, vec_ty, fill, f);
|
ret iter_vec_uniq(bcx, vptr, vec_ty, fill, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user