Skip to content

Commit 9a15d66

Browse files
committed
Omit lifetime intrinsics for function arguments and similar top-level items
Function arguments are live for the whole function scope, so adding lifetime intrinsics around them adds no value. The same is true for drop hint allocas and everything else that goes directly through lvalue_scratch_datum. So the easiest fix is to emit lifetime intrinsics only for lvalue datums that are created in to_lvalue_datum_in_scope(). The reduces peak memory usage and LLVM times by about 1-4%, depending on the crate.
1 parent 727a5d5 commit 9a15d66

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/librustc_trans/trans/datum.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@ pub fn lvalue_scratch_datum<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
304304
let scratch = alloc_ty(bcx, ty, name);
305305

306306
// Subtle. Populate the scratch memory *before* scheduling cleanup.
307-
call_lifetime_start(bcx, scratch);
308307
let bcx = populate(arg, bcx, scratch);
309-
bcx.fcx.schedule_lifetime_end(scope, scratch);
310308
bcx.fcx.schedule_drop_mem(scope, scratch, ty, None);
311309

312310
DatumBlock::new(bcx, Datum::new(scratch, ty, Lvalue::new("datum::lvalue_scratch_datum")))
@@ -499,7 +497,12 @@ impl<'tcx> Datum<'tcx, Rvalue> {
499497
ByValue => {
500498
lvalue_scratch_datum(
501499
bcx, self.ty, name, scope, self,
502-
|this, bcx, llval| this.store_to(bcx, llval))
500+
|this, bcx, llval| {
501+
call_lifetime_start(bcx, llval);
502+
let bcx = this.store_to(bcx, llval);
503+
bcx.fcx.schedule_lifetime_end(scope, llval);
504+
bcx
505+
})
503506
}
504507
}
505508
}

0 commit comments

Comments
 (0)