Cache dominators.

This commit is contained in:
Camille GILLOT 2023-05-04 16:26:09 +00:00
parent aa1267f630
commit 6f271dc49c
6 changed files with 19 additions and 19 deletions

View File

@ -2382,7 +2382,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let mut back_edge_stack = Vec::new();
predecessor_locations(self.body, location).for_each(|predecessor| {
if location.dominates(predecessor, self.dominators()) {
if location.dominates(predecessor, self.dominators) {
back_edge_stack.push(predecessor)
} else {
stack.push(predecessor);
@ -2494,7 +2494,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let mut has_predecessor = false;
predecessor_locations(self.body, location).for_each(|predecessor| {
if location.dominates(predecessor, self.dominators()) {
if location.dominates(predecessor, self.dominators) {
back_edge_stack.push(predecessor)
} else {
stack.push(predecessor);

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,7 @@ fn do_mir_borrowck<'tcx>(
used_mut: Default::default(),
used_mut_upvars: SmallVec::new(),
borrow_set: Rc::clone(&borrow_set),
dominators: Default::default(),
dominators: promoted_body.basic_blocks.dominators(),
upvars: Vec::new(),
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
region_names: RefCell::default(),
@ -360,7 +359,7 @@ fn do_mir_borrowck<'tcx>(
used_mut: Default::default(),
used_mut_upvars: SmallVec::new(),
borrow_set: Rc::clone(&borrow_set),
dominators: Default::default(),
dominators: body.basic_blocks.dominators(),
upvars,
local_names,
region_names: RefCell::default(),
@ -592,7 +591,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
borrow_set: Rc<BorrowSet<'tcx>>,
/// Dominators for MIR
dominators: OnceCell<Dominators<BasicBlock>>,
dominators: &'cx Dominators<BasicBlock>,
/// Information about upvars not necessarily preserved in types or MIR
upvars: Vec<Upvar<'tcx>>,
@ -1103,7 +1102,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(Read(kind), BorrowKind::Unique | BorrowKind::Mut { .. }) => {
// Reading from mere reservations of mutable-borrows is OK.
if !is_active(this.dominators(), borrow, location) {
if !is_active(this.dominators, borrow, location) {
assert!(allow_two_phase_borrow(borrow.kind));
return Control::Continue;
}
@ -2267,10 +2266,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option<FieldIdx> {
path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body())
}
fn dominators(&self) -> &Dominators<BasicBlock> {
self.dominators.get_or_init(|| self.body.basic_blocks.dominators())
}
}
mod error {

View File

@ -84,7 +84,7 @@ impl DefLocation {
struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
fx: &'mir FunctionCx<'a, 'tcx, Bx>,
dominators: Dominators<mir::BasicBlock>,
dominators: &'mir Dominators<mir::BasicBlock>,
locals: IndexVec<mir::Local, LocalKind>,
}

View File

@ -28,6 +28,8 @@ struct Cache {
switch_sources: OnceCell<SwitchSources>,
is_cyclic: OnceCell<bool>,
postorder: OnceCell<Vec<BasicBlock>>,
dominator_tree: OnceCell<DominatorTree<BasicBlock>>,
dominators: OnceCell<Dominators<BasicBlock>>,
}
impl<'tcx> BasicBlocks<'tcx> {
@ -42,12 +44,12 @@ impl<'tcx> BasicBlocks<'tcx> {
*self.cache.is_cyclic.get_or_init(|| graph::is_cyclic(self))
}
pub fn dominator_tree(&self) -> DominatorTree<BasicBlock> {
dominator_tree(&self)
pub fn dominator_tree(&self) -> &DominatorTree<BasicBlock> {
self.cache.dominator_tree.get_or_init(|| dominator_tree(&self))
}
pub fn dominators(&self) -> Dominators<BasicBlock> {
dominators(&self.dominator_tree())
pub fn dominators(&self) -> &Dominators<BasicBlock> {
self.cache.dominators.get_or_init(|| dominators(self.dominator_tree()))
}
/// Returns predecessors for each basic block.

View File

@ -68,8 +68,11 @@ impl SsaLocals {
let assignment_order = Vec::with_capacity(body.local_decls.len());
let assignments = IndexVec::from_elem(Set1::Empty, &body.local_decls);
let dominators =
if body.basic_blocks.len() > 2 { Some(body.basic_blocks.dominators()) } else { None };
let dominators = if body.basic_blocks.len() > 2 {
Some(body.basic_blocks.dominators().clone())
} else {
None
};
let dominators = SmallDominators { inner: dominators };
let direct_uses = IndexVec::from_elem(0, &body.local_decls);