Skip to content

Commit 7911d99

Browse files
committed
Auto merge of #27221 - dotdash:no_empty_clean, r=luqmana
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).
2 parents 2e5b165 + a66af87 commit 7911d99

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/librustc_trans/trans/cleanup.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -774,20 +774,22 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx
774774
// At this point, `popped_scopes` is empty, and so the final block
775775
// that we return to the user is `Cleanup(AST 24)`.
776776
while let Some(mut scope) = popped_scopes.pop() {
777-
let name = scope.block_name("clean");
778-
debug!("generating cleanups for {}", name);
779-
let bcx_in = self.new_block(label.is_unwind(),
780-
&name[..],
781-
None);
782-
let mut bcx_out = bcx_in;
783-
for cleanup in scope.cleanups.iter().rev() {
784-
bcx_out = cleanup.trans(bcx_out,
785-
scope.debug_loc);
786-
}
787-
build::Br(bcx_out, prev_llbb, DebugLoc::None);
788-
prev_llbb = bcx_in.llbb;
777+
if !scope.cleanups.is_empty() {
778+
let name = scope.block_name("clean");
779+
debug!("generating cleanups for {}", name);
780+
let bcx_in = self.new_block(label.is_unwind(),
781+
&name[..],
782+
None);
783+
let mut bcx_out = bcx_in;
784+
for cleanup in scope.cleanups.iter().rev() {
785+
bcx_out = cleanup.trans(bcx_out,
786+
scope.debug_loc);
787+
}
788+
build::Br(bcx_out, prev_llbb, DebugLoc::None);
789+
prev_llbb = bcx_in.llbb;
789790

790-
scope.add_cached_early_exit(label, prev_llbb);
791+
scope.add_cached_early_exit(label, prev_llbb);
792+
}
791793
self.push_scope(scope);
792794
}
793795

0 commit comments

Comments
 (0)