Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocess and cache dominator tree #111673

Merged
merged 9 commits into from
May 24, 2023
Merged
Prev Previous commit
Next Next commit
Do not clone dominator tree for SSA analysis.
  • Loading branch information
cjgillot committed May 17, 2023
commit ada7f1c2c4900877bac0082ac5482e86b3b3974c
19 changes: 8 additions & 11 deletions compiler/rustc_mir_transform/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub struct SsaLocals {
/// We often encounter MIR bodies with 1 or 2 basic blocks. In those cases, it's unnecessary to
/// actually compute dominators, we can just compare block indices because bb0 is always the first
/// block, and in any body all other blocks are always dominated by bb0.
struct SmallDominators {
inner: Option<Dominators<BasicBlock>>,
struct SmallDominators<'a> {
inner: Option<&'a Dominators<BasicBlock>>,
}

impl SmallDominators {
impl SmallDominators<'_> {
fn dominates(&self, first: Location, second: Location) -> bool {
if first.block == second.block {
first.statement_index <= second.statement_index
Expand Down Expand Up @@ -68,11 +68,8 @@ 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().clone())
} else {
None
};
let dominators =
if body.basic_blocks.len() > 2 { Some(body.basic_blocks.dominators()) } else { None };
let dominators = SmallDominators { inner: dominators };

let direct_uses = IndexVec::from_elem(0, &body.local_decls);
Expand Down Expand Up @@ -201,14 +198,14 @@ enum LocationExtended {
Arg,
}

struct SsaVisitor {
dominators: SmallDominators,
struct SsaVisitor<'a> {
dominators: SmallDominators<'a>,
assignments: IndexVec<Local, Set1<LocationExtended>>,
assignment_order: Vec<Local>,
direct_uses: IndexVec<Local, u32>,
}

impl<'tcx> Visitor<'tcx> for SsaVisitor {
impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
fn visit_local(&mut self, local: Local, ctxt: PlaceContext, loc: Location) {
match ctxt {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
Expand Down