From a66af8788d904a2c197803d5289de01274010891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Wed, 22 Jul 2015 23:15:01 +0200 Subject: [PATCH] Avoid creating basic blocks for empty cleanup scopes When compiling libsyntax this removes about 30k basic blocks that only contain a single unconditional jump and reduces the peak memory usage by about 10MB (from 681MB down to 671MB). --- src/librustc_trans/trans/cleanup.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/librustc_trans/trans/cleanup.rs b/src/librustc_trans/trans/cleanup.rs index 37722d5a549f..0d4971203193 100644 --- a/src/librustc_trans/trans/cleanup.rs +++ b/src/librustc_trans/trans/cleanup.rs @@ -774,20 +774,22 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx // At this point, `popped_scopes` is empty, and so the final block // that we return to the user is `Cleanup(AST 24)`. while let Some(mut scope) = popped_scopes.pop() { - let name = scope.block_name("clean"); - debug!("generating cleanups for {}", name); - let bcx_in = self.new_block(label.is_unwind(), - &name[..], - None); - let mut bcx_out = bcx_in; - for cleanup in scope.cleanups.iter().rev() { - bcx_out = cleanup.trans(bcx_out, - scope.debug_loc); - } - build::Br(bcx_out, prev_llbb, DebugLoc::None); - prev_llbb = bcx_in.llbb; + if !scope.cleanups.is_empty() { + let name = scope.block_name("clean"); + debug!("generating cleanups for {}", name); + let bcx_in = self.new_block(label.is_unwind(), + &name[..], + None); + let mut bcx_out = bcx_in; + for cleanup in scope.cleanups.iter().rev() { + bcx_out = cleanup.trans(bcx_out, + scope.debug_loc); + } + build::Br(bcx_out, prev_llbb, DebugLoc::None); + prev_llbb = bcx_in.llbb; - scope.add_cached_early_exit(label, prev_llbb); + scope.add_cached_early_exit(label, prev_llbb); + } self.push_scope(scope); }