Cache dominators.
This commit is contained in:
parent
aa1267f630
commit
6f271dc49c
@ -2382,7 +2382,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
let mut back_edge_stack = Vec::new();
|
let mut back_edge_stack = Vec::new();
|
||||||
|
|
||||||
predecessor_locations(self.body, location).for_each(|predecessor| {
|
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)
|
back_edge_stack.push(predecessor)
|
||||||
} else {
|
} else {
|
||||||
stack.push(predecessor);
|
stack.push(predecessor);
|
||||||
@ -2494,7 +2494,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
|
|
||||||
let mut has_predecessor = false;
|
let mut has_predecessor = false;
|
||||||
predecessor_locations(self.body, location).for_each(|predecessor| {
|
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)
|
back_edge_stack.push(predecessor)
|
||||||
} else {
|
} else {
|
||||||
stack.push(predecessor);
|
stack.push(predecessor);
|
||||||
|
@ -46,7 +46,7 @@ struct InvalidationGenerator<'cx, 'tcx> {
|
|||||||
all_facts: &'cx mut AllFacts,
|
all_facts: &'cx mut AllFacts,
|
||||||
location_table: &'cx LocationTable,
|
location_table: &'cx LocationTable,
|
||||||
body: &'cx Body<'tcx>,
|
body: &'cx Body<'tcx>,
|
||||||
dominators: Dominators<BasicBlock>,
|
dominators: &'cx Dominators<BasicBlock>,
|
||||||
borrow_set: &'cx BorrowSet<'tcx>,
|
borrow_set: &'cx BorrowSet<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ use rustc_target::abi::FieldIdx;
|
|||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::cell::OnceCell;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
@ -331,7 +330,7 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
used_mut: Default::default(),
|
used_mut: Default::default(),
|
||||||
used_mut_upvars: SmallVec::new(),
|
used_mut_upvars: SmallVec::new(),
|
||||||
borrow_set: Rc::clone(&borrow_set),
|
borrow_set: Rc::clone(&borrow_set),
|
||||||
dominators: Default::default(),
|
dominators: promoted_body.basic_blocks.dominators(),
|
||||||
upvars: Vec::new(),
|
upvars: Vec::new(),
|
||||||
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
|
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
|
||||||
region_names: RefCell::default(),
|
region_names: RefCell::default(),
|
||||||
@ -360,7 +359,7 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
used_mut: Default::default(),
|
used_mut: Default::default(),
|
||||||
used_mut_upvars: SmallVec::new(),
|
used_mut_upvars: SmallVec::new(),
|
||||||
borrow_set: Rc::clone(&borrow_set),
|
borrow_set: Rc::clone(&borrow_set),
|
||||||
dominators: Default::default(),
|
dominators: body.basic_blocks.dominators(),
|
||||||
upvars,
|
upvars,
|
||||||
local_names,
|
local_names,
|
||||||
region_names: RefCell::default(),
|
region_names: RefCell::default(),
|
||||||
@ -592,7 +591,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
borrow_set: Rc<BorrowSet<'tcx>>,
|
borrow_set: Rc<BorrowSet<'tcx>>,
|
||||||
|
|
||||||
/// Dominators for MIR
|
/// Dominators for MIR
|
||||||
dominators: OnceCell<Dominators<BasicBlock>>,
|
dominators: &'cx Dominators<BasicBlock>,
|
||||||
|
|
||||||
/// Information about upvars not necessarily preserved in types or MIR
|
/// Information about upvars not necessarily preserved in types or MIR
|
||||||
upvars: Vec<Upvar<'tcx>>,
|
upvars: Vec<Upvar<'tcx>>,
|
||||||
@ -1103,7 +1102,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
|
|
||||||
(Read(kind), BorrowKind::Unique | BorrowKind::Mut { .. }) => {
|
(Read(kind), BorrowKind::Unique | BorrowKind::Mut { .. }) => {
|
||||||
// Reading from mere reservations of mutable-borrows is OK.
|
// 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));
|
assert!(allow_two_phase_borrow(borrow.kind));
|
||||||
return Control::Continue;
|
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> {
|
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())
|
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 {
|
mod error {
|
||||||
|
@ -84,7 +84,7 @@ impl DefLocation {
|
|||||||
|
|
||||||
struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
|
struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
|
||||||
fx: &'mir FunctionCx<'a, 'tcx, Bx>,
|
fx: &'mir FunctionCx<'a, 'tcx, Bx>,
|
||||||
dominators: Dominators<mir::BasicBlock>,
|
dominators: &'mir Dominators<mir::BasicBlock>,
|
||||||
locals: IndexVec<mir::Local, LocalKind>,
|
locals: IndexVec<mir::Local, LocalKind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ struct Cache {
|
|||||||
switch_sources: OnceCell<SwitchSources>,
|
switch_sources: OnceCell<SwitchSources>,
|
||||||
is_cyclic: OnceCell<bool>,
|
is_cyclic: OnceCell<bool>,
|
||||||
postorder: OnceCell<Vec<BasicBlock>>,
|
postorder: OnceCell<Vec<BasicBlock>>,
|
||||||
|
dominator_tree: OnceCell<DominatorTree<BasicBlock>>,
|
||||||
|
dominators: OnceCell<Dominators<BasicBlock>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> BasicBlocks<'tcx> {
|
impl<'tcx> BasicBlocks<'tcx> {
|
||||||
@ -42,12 +44,12 @@ impl<'tcx> BasicBlocks<'tcx> {
|
|||||||
*self.cache.is_cyclic.get_or_init(|| graph::is_cyclic(self))
|
*self.cache.is_cyclic.get_or_init(|| graph::is_cyclic(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dominator_tree(&self) -> DominatorTree<BasicBlock> {
|
pub fn dominator_tree(&self) -> &DominatorTree<BasicBlock> {
|
||||||
dominator_tree(&self)
|
self.cache.dominator_tree.get_or_init(|| dominator_tree(&self))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dominators(&self) -> Dominators<BasicBlock> {
|
pub fn dominators(&self) -> &Dominators<BasicBlock> {
|
||||||
dominators(&self.dominator_tree())
|
self.cache.dominators.get_or_init(|| dominators(self.dominator_tree()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns predecessors for each basic block.
|
/// Returns predecessors for each basic block.
|
||||||
|
@ -68,8 +68,11 @@ impl SsaLocals {
|
|||||||
let assignment_order = Vec::with_capacity(body.local_decls.len());
|
let assignment_order = Vec::with_capacity(body.local_decls.len());
|
||||||
|
|
||||||
let assignments = IndexVec::from_elem(Set1::Empty, &body.local_decls);
|
let assignments = IndexVec::from_elem(Set1::Empty, &body.local_decls);
|
||||||
let dominators =
|
let dominators = if body.basic_blocks.len() > 2 {
|
||||||
if body.basic_blocks.len() > 2 { Some(body.basic_blocks.dominators()) } else { None };
|
Some(body.basic_blocks.dominators().clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
let dominators = SmallDominators { inner: dominators };
|
let dominators = SmallDominators { inner: dominators };
|
||||||
|
|
||||||
let direct_uses = IndexVec::from_elem(0, &body.local_decls);
|
let direct_uses = IndexVec::from_elem(0, &body.local_decls);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user