trans::glue: don't allocate a pointer variable if it already exists

Removes one alloca and store from the drop glue of @ boxes. This speeds
up the rustc build by 1s (might be noise, though).
This commit is contained in:
Philipp Brüschweiler 2013-06-15 18:21:15 +02:00
parent eadd83da8b
commit 3f69e20043
2 changed files with 17 additions and 7 deletions

View File

@ -552,7 +552,7 @@ pub fn make_opaque_cbox_drop_glue(
ast::BorrowedSigil => bcx, ast::BorrowedSigil => bcx,
ast::ManagedSigil => { ast::ManagedSigil => {
glue::decr_refcnt_maybe_free( glue::decr_refcnt_maybe_free(
bcx, Load(bcx, cboxptr), bcx, Load(bcx, cboxptr), Some(cboxptr),
ty::mk_opaque_closure_ptr(bcx.tcx(), sigil)) ty::mk_opaque_closure_ptr(bcx.tcx(), sigil))
} }
ast::OwnedSigil => { ast::OwnedSigil => {

View File

@ -103,7 +103,7 @@ pub fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
ty::ty_box(_) | ty::ty_opaque_box | ty::ty_box(_) | ty::ty_opaque_box |
ty::ty_evec(_, ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) |
ty::ty_estr(ty::vstore_box) => { ty::ty_estr(ty::vstore_box) => {
decr_refcnt_maybe_free(bcx, v, t) decr_refcnt_maybe_free(bcx, v, None, t)
} }
_ => bcx.tcx().sess.bug("drop_ty_immediate: non-box ty") _ => bcx.tcx().sess.bug("drop_ty_immediate: non-box ty")
} }
@ -520,7 +520,7 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
let bcx = match ty::get(t).sty { let bcx = match ty::get(t).sty {
ty::ty_box(_) | ty::ty_opaque_box | ty::ty_box(_) | ty::ty_opaque_box |
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => { ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
decr_refcnt_maybe_free(bcx, Load(bcx, v0), t) decr_refcnt_maybe_free(bcx, Load(bcx, v0), Some(v0), t)
} }
ty::ty_uniq(_) | ty::ty_uniq(_) |
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => { ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
@ -545,8 +545,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
closure::make_closure_glue(bcx, v0, t, drop_ty) closure::make_closure_glue(bcx, v0, t, drop_ty)
} }
ty::ty_trait(_, _, ty::BoxTraitStore, _) => { ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
let llbox = Load(bcx, GEPi(bcx, v0, [0u, abi::trt_field_box])); let llbox_ptr = GEPi(bcx, v0, [0u, abi::trt_field_box]);
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx)) let llbox = Load(bcx, llbox_ptr);
decr_refcnt_maybe_free(bcx, llbox, Some(llbox_ptr),
ty::mk_opaque_box(ccx.tcx))
} }
ty::ty_trait(_, _, ty::UniqTraitStore, _) => { ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]); let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
@ -580,7 +582,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
build_return(bcx); build_return(bcx);
} }
pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t) // box_ptr_ptr is optional, it is constructed if not supplied.
pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef,
box_ptr_ptr: Option<ValueRef>,
t: ty::t)
-> block { -> block {
let _icx = bcx.insn_ctxt("decr_refcnt_maybe_free"); let _icx = bcx.insn_ctxt("decr_refcnt_maybe_free");
let ccx = bcx.ccx(); let ccx = bcx.ccx();
@ -590,7 +595,12 @@ pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t)
let rc = Sub(bcx, Load(bcx, rc_ptr), C_int(ccx, 1)); let rc = Sub(bcx, Load(bcx, rc_ptr), C_int(ccx, 1));
Store(bcx, rc, rc_ptr); Store(bcx, rc, rc_ptr);
let zero_test = ICmp(bcx, lib::llvm::IntEQ, C_int(ccx, 0), rc); let zero_test = ICmp(bcx, lib::llvm::IntEQ, C_int(ccx, 0), rc);
with_cond(bcx, zero_test, |bcx| free_ty_immediate(bcx, box_ptr, t)) do with_cond(bcx, zero_test) |bcx| {
match box_ptr_ptr {
Some(p) => free_ty(bcx, p, t),
None => free_ty_immediate(bcx, box_ptr, t)
}
}
} }
} }