Skip to content

Commit d0f88cd

Browse files
committed
auto merge of #7155 : Blei/rust/drop-glue-alloca, r=graydon
Removes one alloca and store from the drop glue of @ boxes. This speeds up the rustc build by 1s (might be noise, though).
2 parents 08c1155 + 3f69e20 commit d0f88cd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/librustc/middle/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ pub fn make_opaque_cbox_drop_glue(
553553
ast::BorrowedSigil => bcx,
554554
ast::ManagedSigil => {
555555
glue::decr_refcnt_maybe_free(
556-
bcx, Load(bcx, cboxptr),
556+
bcx, Load(bcx, cboxptr), Some(cboxptr),
557557
ty::mk_opaque_closure_ptr(bcx.tcx(), sigil))
558558
}
559559
ast::OwnedSigil => {

src/librustc/middle/trans/glue.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
103103
ty::ty_box(_) | ty::ty_opaque_box |
104104
ty::ty_evec(_, ty::vstore_box) |
105105
ty::ty_estr(ty::vstore_box) => {
106-
decr_refcnt_maybe_free(bcx, v, t)
106+
decr_refcnt_maybe_free(bcx, v, None, t)
107107
}
108108
_ => bcx.tcx().sess.bug("drop_ty_immediate: non-box ty")
109109
}
@@ -489,7 +489,7 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
489489
let bcx = match ty::get(t).sty {
490490
ty::ty_box(_) | ty::ty_opaque_box |
491491
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
492-
decr_refcnt_maybe_free(bcx, Load(bcx, v0), t)
492+
decr_refcnt_maybe_free(bcx, Load(bcx, v0), Some(v0), t)
493493
}
494494
ty::ty_uniq(_) |
495495
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
@@ -514,8 +514,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
514514
closure::make_closure_glue(bcx, v0, t, drop_ty)
515515
}
516516
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
517-
let llbox = Load(bcx, GEPi(bcx, v0, [0u, abi::trt_field_box]));
518-
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
517+
let llbox_ptr = GEPi(bcx, v0, [0u, abi::trt_field_box]);
518+
let llbox = Load(bcx, llbox_ptr);
519+
decr_refcnt_maybe_free(bcx, llbox, Some(llbox_ptr),
520+
ty::mk_opaque_box(ccx.tcx))
519521
}
520522
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
521523
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
@@ -549,7 +551,10 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
549551
build_return(bcx);
550552
}
551553

552-
pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t)
554+
// box_ptr_ptr is optional, it is constructed if not supplied.
555+
pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef,
556+
box_ptr_ptr: Option<ValueRef>,
557+
t: ty::t)
553558
-> block {
554559
let _icx = bcx.insn_ctxt("decr_refcnt_maybe_free");
555560
let ccx = bcx.ccx();
@@ -559,7 +564,12 @@ pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef, t: ty::t)
559564
let rc = Sub(bcx, Load(bcx, rc_ptr), C_int(ccx, 1));
560565
Store(bcx, rc, rc_ptr);
561566
let zero_test = ICmp(bcx, lib::llvm::IntEQ, C_int(ccx, 0), rc);
562-
with_cond(bcx, zero_test, |bcx| free_ty_immediate(bcx, box_ptr, t))
567+
do with_cond(bcx, zero_test) |bcx| {
568+
match box_ptr_ptr {
569+
Some(p) => free_ty(bcx, p, t),
570+
None => free_ty_immediate(bcx, box_ptr, t)
571+
}
572+
}
563573
}
564574
}
565575

0 commit comments

Comments
 (0)