Skip to content

Commit e7e8f6d

Browse files
committed
Pre-cache traversals in mir_promoted.
1 parent f04db50 commit e7e8f6d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ impl<'tcx> BasicBlocks<'tcx> {
5252
BasicBlocks { basic_blocks, cache: Cache::default() }
5353
}
5454

55+
/// Force caching of traversals.
56+
pub fn cache_traversals(&self) {
57+
let _ = self.predecessors();
58+
let _ = self.switch_sources();
59+
let _ = self.reverse_postorder();
60+
let _ = self.dominators();
61+
}
62+
63+
#[inline]
5564
pub fn dominators(&self) -> &Dominators<BasicBlock> {
5665
self.cache.dominators.get_or_init(|| dominators(self))
5766
}

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ fn mir_promoted(
446446
pm::Optimizations::Allowed,
447447
);
448448

449+
// The returned MIR will be used for analyses. Make sure that the traversals are computed
450+
// early, so we don't have to re-run them.
451+
body.basic_blocks.cache_traversals();
452+
449453
lint_tail_expr_drop_order::run_lint(tcx, def, &body);
450454

451455
let promoted = promote_pass.promoted_fragments.into_inner();

0 commit comments

Comments
 (0)