diff options
| author | Michael Sullivan <sully@msully.net> | 2012-06-12 16:41:20 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2012-06-12 17:01:13 -0700 |
| commit | 35dd717352caad82371764bf2a2ce675164aaf0a (patch) | |
| tree | 3a2c0a2de0ae46b9d06fb02fdc8b38b122480270 | |
| parent | ccf4e8cf9acd555c90176e46ae21ef10337d31d5 (diff) | |
| download | rust-35dd717352caad82371764bf2a2ce675164aaf0a.tar.gz rust-35dd717352caad82371764bf2a2ce675164aaf0a.zip | |
Simplify a bunch of trans functions to not need the rust type. Remove some PointerCasts.
| -rw-r--r-- | src/rustc/middle/trans/alt.rs | 6 | ||||
| -rw-r--r-- | src/rustc/middle/trans/base.rs | 20 | ||||
| -rw-r--r-- | src/rustc/middle/trans/tvec.rs | 73 |
3 files changed, 33 insertions, 66 deletions
diff --git a/src/rustc/middle/trans/alt.rs b/src/rustc/middle/trans/alt.rs index 44f26ad6947..2fd4374dc09 100644 --- a/src/rustc/middle/trans/alt.rs +++ b/src/rustc/middle/trans/alt.rs @@ -462,8 +462,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef], // Unbox in case of a box field if any_box_pat(m, col) { let box = Load(bcx, val); - let box_ty = node_id_type(bcx, pat_id); - let box_no_addrspace = non_gc_box_cast(bcx, box, box_ty); + let box_no_addrspace = non_gc_box_cast(bcx, box); let unboxed = GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]); compile_submatch(bcx, enter_box(dm, m, col, val), [unboxed] + vals_left, chk, exits); @@ -472,8 +471,7 @@ fn compile_submatch(bcx: block, m: match, vals: [ValueRef], if any_uniq_pat(m, col) { let box = Load(bcx, val); - let box_ty = node_id_type(bcx, pat_id); - let box_no_addrspace = non_gc_box_cast(bcx, box, box_ty); + let box_no_addrspace = non_gc_box_cast(bcx, box); let unboxed = GEPi(bcx, box_no_addrspace, [0u, abi::box_field_body]); compile_submatch(bcx, enter_uniq(dm, m, col, val), [unboxed] + vals_left, chk, exits); diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 70d30c45da5..fe4046c3663 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -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) -> {box: ValueRef, body: ValueRef} { 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 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]); 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 val = alt check ty::get(t).struct { 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]) } 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]) } 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 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"); 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) } @@ -3885,11 +3884,8 @@ fn trans_fail_expr(bcx: block, sp_opt: option<span>, bcx = expr_res.bcx; if ty::type_is_str(e_ty) { - let unit_ty = ty::mk_mach_uint(tcx, ast::ty_u8); - let vec_ty = ty::mk_vec(tcx, {ty: unit_ty, mutbl: ast::m_imm}); - 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); + let body = tvec::get_bodyptr(bcx, expr_res.val); + let data = tvec::get_dataptr(bcx, body); ret trans_fail_value(bcx, sp_opt, data); } else if bcx.unreachable || ty::type_is_bot(e_ty) { ret bcx; diff --git a/src/rustc/middle/trans/tvec.rs b/src/rustc/middle/trans/tvec.rs index 125fc8d30df..b220ec7cd42 100644 --- a/src/rustc/middle/trans/tvec.rs +++ b/src/rustc/middle/trans/tvec.rs @@ -5,11 +5,12 @@ import back::abi; import base::{call_memmove, INIT, copy_val, load_if_immediate, get_tydesc, sub_block, do_spill_noroot, - dest, bcx_icx}; + dest, bcx_icx, non_gc_box_cast}; import syntax::codemap::span; import shape::llsize_of; import build::*; import common::*; +import util::ppaux::ty_to_str; fn get_fill(bcx: block, vptr: ValueRef) -> ValueRef { 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])) } -fn get_bodyptr(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> ValueRef { - let ccx = bcx.ccx(); - 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_bodyptr(bcx: block, vptr: ValueRef) -> ValueRef { + non_gc_box_cast(bcx, GEPi(bcx, vptr, [0u, abi::box_field_body])) } -fn get_dataptr(bcx: block, vptr: ValueRef, unit_ty: TypeRef) +fn get_dataptr(bcx: block, vptr: ValueRef) -> ValueRef { let _icx = bcx.insn_ctxt("tvec::get_dataptr"); - let ptr = GEPi(bcx, vptr, [0u, abi::vec_elt_elems]); - PointerCast(bcx, ptr, T_ptr(unit_ty)) + GEPi(bcx, vptr, [0u, abi::vec_elt_elems, 0u]) } 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 { let _icx = bcx.insn_ctxt("tvec::duplicate_uniq"); 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 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 { let {bcx, val} = alloc_uniq(bcx, unit_ty, args.len()); add_clean_free(bcx, val, true); - let body = get_bodyptr(bcx, val, vec_ty); - let dataptr = get_dataptr(bcx, body, llunitty); + let dataptr = get_dataptr(bcx, get_bodyptr(bcx, val)); {bcx: bcx, val: val, dataptr: dataptr} } ast::vstore_box { @@ -241,10 +227,8 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t) (base, len) } ty::vstore_uniq { - let body = tvec::get_bodyptr(cx, v, vec_ty); - let base = tvec::get_dataptr(cx, body, llunitty); - let len = tvec::get_fill(cx, body); - (base, len) + let body = tvec::get_bodyptr(cx, v); + (tvec::get_dataptr(cx, body), tvec::get_fill(cx, body)) } ty::vstore_box { 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 unit_ty = ty::sequence_element_type(ccx.tcx, 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 self_append = ICmp(bcx, lib::llvm::IntEQ, lhs, rhs); - let lbody = get_bodyptr(bcx, lhs, vec_ty); - let rbody = get_bodyptr(bcx, rhs, vec_ty); - let lfill = get_fill(bcx, lbody); - let rfill = get_fill(bcx, rbody); + let lfill = get_fill(bcx, get_bodyptr(bcx, lhs)); + let rfill = get_fill(bcx, get_bodyptr(bcx, rhs)); let mut new_fill = Add(bcx, lfill, rfill); if strings { new_fill = Sub(bcx, new_fill, C_int(ccx, 1)); } 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 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; if strings { lhs_off = Sub(bcx, lhs_off, C_int(ccx, 1)); } 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); for vec::each(vals) {|val| 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 new_fill = Add(bcx, old_fill, elt_sz); 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]); 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); - let targetptr = pointer_add(bcx, get_dataptr(bcx, vptr, elt_llty), + let targetptr = pointer_add(bcx, get_dataptr(bcx, vptr), old_fill); 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); } - let lhs_body = get_bodyptr(bcx, lhs, vec_ty); - let rhs_body = get_bodyptr(bcx, rhs, vec_ty); - - let lhs_fill = get_fill(bcx, lhs_body); - let rhs_fill = get_fill(bcx, rhs_body); + let lhs_fill = get_fill(bcx, get_bodyptr(bcx, lhs)); + let rhs_fill = get_fill(bcx, get_bodyptr(bcx, rhs)); let new_fill = Add(bcx, lhs_fill, rhs_fill); let mut {bcx: bcx, val: new_vec_ptr} = 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 - (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, _ty: ty::t) -> block { 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, fill: ValueRef, f: iter_vec_block) -> block { let _icx = bcx.insn_ctxt("tvec::iter_vec_uniq"); - let ccx = bcx.ccx(); - 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); + let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr)); iter_vec_raw(bcx, data_ptr, vec_ty, fill, f) } fn iter_vec(bcx: block, vptr: ValueRef, vec_ty: ty::t, f: iter_vec_block) -> block { let _icx = bcx.insn_ctxt("tvec::iter_vec"); - let body_ptr = get_bodyptr(bcx, vptr, vec_ty); - let fill = get_fill(bcx, body_ptr); + let fill = get_fill(bcx, get_bodyptr(bcx, vptr)); ret iter_vec_uniq(bcx, vptr, vec_ty, fill, f); } |
