Skip to content

Commit eaafb25

Browse files
committed
Replace LocationExtended with DefLocation in SsaLocals
1 parent 4357482 commit eaafb25

File tree

1 file changed

+11
-27
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+11
-27
lines changed

Diff for: compiler/rustc_mir_transform/src/ssa.rs

+11-27
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::mir::*;
1515

1616
pub struct SsaLocals {
1717
/// Assignments to each local. This defines whether the local is SSA.
18-
assignments: IndexVec<Local, Set1<LocationExtended>>,
18+
assignments: IndexVec<Local, Set1<DefLocation>>,
1919
/// We visit the body in reverse postorder, to ensure each local is assigned before it is used.
2020
/// We remember the order in which we saw the assignments to compute the SSA values in a single
2121
/// pass.
@@ -38,7 +38,7 @@ impl SsaLocals {
3838
let mut visitor = SsaVisitor { assignments, assignment_order, dominators, direct_uses };
3939

4040
for local in body.args_iter() {
41-
visitor.assignments[local] = Set1::One(LocationExtended::Arg);
41+
visitor.assignments[local] = Set1::One(DefLocation::Argument);
4242
}
4343

4444
// For SSA assignments, a RPO visit will see the assignment before it sees any use.
@@ -94,14 +94,7 @@ impl SsaLocals {
9494
location: Location,
9595
) -> bool {
9696
match self.assignments[local] {
97-
Set1::One(LocationExtended::Arg) => true,
98-
Set1::One(LocationExtended::Plain(ass)) => {
99-
if ass.block == location.block {
100-
ass.statement_index < location.statement_index
101-
} else {
102-
dominators.dominates(ass.block, location.block)
103-
}
104-
}
97+
Set1::One(def) => def.dominates(location, dominators),
10598
_ => false,
10699
}
107100
}
@@ -111,7 +104,7 @@ impl SsaLocals {
111104
body: &'a Body<'tcx>,
112105
) -> impl Iterator<Item = (Local, &'a Rvalue<'tcx>, Location)> + 'a {
113106
self.assignment_order.iter().filter_map(|&local| {
114-
if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] {
107+
if let Set1::One(DefLocation::Body(loc)) = self.assignments[local] {
115108
// `loc` must point to a direct assignment to `local`.
116109
let Either::Left(stmt) = body.stmt_at(loc) else { bug!() };
117110
let Some((target, rvalue)) = stmt.kind.as_assign() else { bug!() };
@@ -129,7 +122,7 @@ impl SsaLocals {
129122
mut f: impl FnMut(Local, &mut Rvalue<'tcx>, Location),
130123
) {
131124
for &local in &self.assignment_order {
132-
if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] {
125+
if let Set1::One(DefLocation::Body(loc)) = self.assignments[local] {
133126
// `loc` must point to a direct assignment to `local`.
134127
let bbs = basic_blocks.as_mut_preserves_cfg();
135128
let bb = &mut bbs[loc.block];
@@ -187,15 +180,9 @@ impl SsaLocals {
187180
}
188181
}
189182

190-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
191-
enum LocationExtended {
192-
Plain(Location),
193-
Arg,
194-
}
195-
196183
struct SsaVisitor<'a> {
197184
dominators: &'a Dominators<BasicBlock>,
198-
assignments: IndexVec<Local, Set1<LocationExtended>>,
185+
assignments: IndexVec<Local, Set1<DefLocation>>,
199186
assignment_order: Vec<Local>,
200187
direct_uses: IndexVec<Local, u32>,
201188
}
@@ -205,10 +192,7 @@ impl SsaVisitor<'_> {
205192
let set = &mut self.assignments[local];
206193
let assign_dominates = match *set {
207194
Set1::Empty | Set1::Many => false,
208-
Set1::One(LocationExtended::Arg) => true,
209-
Set1::One(LocationExtended::Plain(assign)) => {
210-
assign.successor_within_block().dominates(loc, self.dominators)
211-
}
195+
Set1::One(def) => def.dominates(loc, self.dominators),
212196
};
213197
// We are visiting a use that is not dominated by an assignment.
214198
// Either there is a cycle involved, or we are reading for uninitialized local.
@@ -262,7 +246,7 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
262246

263247
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, loc: Location) {
264248
if let Some(local) = place.as_local() {
265-
self.assignments[local].insert(LocationExtended::Plain(loc));
249+
self.assignments[local].insert(DefLocation::Body(loc));
266250
if let Set1::One(_) = self.assignments[local] {
267251
// Only record if SSA-like, to avoid growing the vector needlessly.
268252
self.assignment_order.push(local);
@@ -338,7 +322,7 @@ fn compute_copy_classes(ssa: &mut SsaLocals, body: &Body<'_>) {
338322
#[derive(Debug)]
339323
pub(crate) struct StorageLiveLocals {
340324
/// Set of "StorageLive" statements for each local.
341-
storage_live: IndexVec<Local, Set1<LocationExtended>>,
325+
storage_live: IndexVec<Local, Set1<DefLocation>>,
342326
}
343327

344328
impl StorageLiveLocals {
@@ -348,13 +332,13 @@ impl StorageLiveLocals {
348332
) -> StorageLiveLocals {
349333
let mut storage_live = IndexVec::from_elem(Set1::Empty, &body.local_decls);
350334
for local in always_storage_live_locals.iter() {
351-
storage_live[local] = Set1::One(LocationExtended::Arg);
335+
storage_live[local] = Set1::One(DefLocation::Argument);
352336
}
353337
for (block, bbdata) in body.basic_blocks.iter_enumerated() {
354338
for (statement_index, statement) in bbdata.statements.iter().enumerate() {
355339
if let StatementKind::StorageLive(local) = statement.kind {
356340
storage_live[local]
357-
.insert(LocationExtended::Plain(Location { block, statement_index }));
341+
.insert(DefLocation::Body(Location { block, statement_index }));
358342
}
359343
}
360344
}

0 commit comments

Comments
 (0)