From 9a15d664a67137028bb0d32eab56698b18356e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Tue, 25 Aug 2015 18:33:55 +0200 Subject: [PATCH] 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. --- src/librustc_trans/trans/datum.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_trans/trans/datum.rs b/src/librustc_trans/trans/datum.rs index e0a65c93669c..a57b5d1bbde2 100644 --- a/src/librustc_trans/trans/datum.rs +++ b/src/librustc_trans/trans/datum.rs @@ -304,9 +304,7 @@ pub fn lvalue_scratch_datum<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>, let scratch = alloc_ty(bcx, ty, name); // Subtle. Populate the scratch memory *before* scheduling cleanup. - call_lifetime_start(bcx, scratch); let bcx = populate(arg, bcx, scratch); - bcx.fcx.schedule_lifetime_end(scope, scratch); bcx.fcx.schedule_drop_mem(scope, scratch, ty, None); DatumBlock::new(bcx, Datum::new(scratch, ty, Lvalue::new("datum::lvalue_scratch_datum"))) @@ -499,7 +497,12 @@ impl<'tcx> Datum<'tcx, Rvalue> { ByValue => { lvalue_scratch_datum( bcx, self.ty, name, scope, self, - |this, bcx, llval| this.store_to(bcx, llval)) + |this, bcx, llval| { + call_lifetime_start(bcx, llval); + let bcx = this.store_to(bcx, llval); + bcx.fcx.schedule_lifetime_end(scope, llval); + bcx + }) } } }