1
Fork 0

Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiasko

Preprocess and cache dominator tree

Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344.
That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree).

This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache.

Rebase of https://github.com/rust-lang/rust/pull/107157
cc `@tmiasko`
This commit is contained in:
bors 2023-05-24 16:18:21 +00:00
commit 97d328012b
9 changed files with 107 additions and 51 deletions

View file

@ -46,7 +46,7 @@ struct InvalidationGenerator<'cx, 'tcx> {
all_facts: &'cx mut AllFacts,
location_table: &'cx LocationTable,
body: &'cx Body<'tcx>,
dominators: Dominators<BasicBlock>,
dominators: &'cx Dominators<BasicBlock>,
borrow_set: &'cx BorrowSet<'tcx>,
}

View file

@ -43,7 +43,6 @@ use rustc_target::abi::FieldIdx;
use either::Either;
use smallvec::SmallVec;
use std::cell::OnceCell;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::ops::Deref;
@ -331,7 +330,6 @@ fn do_mir_borrowck<'tcx>(
used_mut: Default::default(),
used_mut_upvars: SmallVec::new(),
borrow_set: Rc::clone(&borrow_set),
dominators: Default::default(),
upvars: Vec::new(),
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
region_names: RefCell::default(),
@ -360,7 +358,6 @@ fn do_mir_borrowck<'tcx>(
used_mut: Default::default(),
used_mut_upvars: SmallVec::new(),
borrow_set: Rc::clone(&borrow_set),
dominators: Default::default(),
upvars,
local_names,
region_names: RefCell::default(),
@ -591,9 +588,6 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
/// The set of borrows extracted from the MIR
borrow_set: Rc<BorrowSet<'tcx>>,
/// Dominators for MIR
dominators: OnceCell<Dominators<BasicBlock>>,
/// Information about upvars not necessarily preserved in types or MIR
upvars: Vec<Upvar<'tcx>>,
@ -2269,7 +2263,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
fn dominators(&self) -> &Dominators<BasicBlock> {
self.dominators.get_or_init(|| self.body.basic_blocks.dominators())
// `BasicBlocks` computes dominators on-demand and caches them.
self.body.basic_blocks.dominators()
}
}