Skip to content

Commit 827dc2a

Browse files
committed
Replace LocationExtended with DefLocation in SsaLocals
1 parent 82ae063 commit 827dc2a

File tree

1 file changed

+13
-19
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+13
-19
lines changed

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

+13-19
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,8 +94,8 @@ impl SsaLocals {
9494
location: Location,
9595
) -> bool {
9696
match self.assignments[local] {
97-
Set1::One(LocationExtended::Arg) => true,
98-
Set1::One(LocationExtended::Plain(ass)) => {
97+
Set1::One(DefLocation::Argument) => true,
98+
Set1::One(DefLocation::Body(ass)) => {
9999
if ass.block == location.block {
100100
ass.statement_index < location.statement_index
101101
} else {
@@ -111,7 +111,7 @@ impl SsaLocals {
111111
body: &'a Body<'tcx>,
112112
) -> impl Iterator<Item = (Local, &'a Rvalue<'tcx>, Location)> + 'a {
113113
self.assignment_order.iter().filter_map(|&local| {
114-
if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] {
114+
if let Set1::One(DefLocation::Body(loc)) = self.assignments[local] {
115115
// `loc` must point to a direct assignment to `local`.
116116
let Either::Left(stmt) = body.stmt_at(loc) else { bug!() };
117117
let Some((target, rvalue)) = stmt.kind.as_assign() else { bug!() };
@@ -129,7 +129,7 @@ impl SsaLocals {
129129
mut f: impl FnMut(Local, &mut Rvalue<'tcx>, Location),
130130
) {
131131
for &local in &self.assignment_order {
132-
if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] {
132+
if let Set1::One(DefLocation::Body(loc)) = self.assignments[local] {
133133
// `loc` must point to a direct assignment to `local`.
134134
let bbs = basic_blocks.as_mut_preserves_cfg();
135135
let bb = &mut bbs[loc.block];
@@ -187,15 +187,9 @@ impl SsaLocals {
187187
}
188188
}
189189

190-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
191-
enum LocationExtended {
192-
Plain(Location),
193-
Arg,
194-
}
195-
196190
struct SsaVisitor<'a> {
197191
dominators: &'a Dominators<BasicBlock>,
198-
assignments: IndexVec<Local, Set1<LocationExtended>>,
192+
assignments: IndexVec<Local, Set1<DefLocation>>,
199193
assignment_order: Vec<Local>,
200194
direct_uses: IndexVec<Local, u32>,
201195
}
@@ -205,8 +199,8 @@ impl SsaVisitor<'_> {
205199
let set = &mut self.assignments[local];
206200
let assign_dominates = match *set {
207201
Set1::Empty | Set1::Many => false,
208-
Set1::One(LocationExtended::Arg) => true,
209-
Set1::One(LocationExtended::Plain(assign)) => {
202+
Set1::One(DefLocation::Argument) => true,
203+
Set1::One(DefLocation::Body(assign)) => {
210204
assign.successor_within_block().dominates(loc, self.dominators)
211205
}
212206
};
@@ -262,7 +256,7 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
262256

263257
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, loc: Location) {
264258
if let Some(local) = place.as_local() {
265-
self.assignments[local].insert(LocationExtended::Plain(loc));
259+
self.assignments[local].insert(DefLocation::Body(loc));
266260
if let Set1::One(_) = self.assignments[local] {
267261
// Only record if SSA-like, to avoid growing the vector needlessly.
268262
self.assignment_order.push(local);
@@ -338,7 +332,7 @@ fn compute_copy_classes(ssa: &mut SsaLocals, body: &Body<'_>) {
338332
#[derive(Debug)]
339333
pub(crate) struct StorageLiveLocals {
340334
/// Set of "StorageLive" statements for each local.
341-
storage_live: IndexVec<Local, Set1<LocationExtended>>,
335+
storage_live: IndexVec<Local, Set1<DefLocation>>,
342336
}
343337

344338
impl StorageLiveLocals {
@@ -348,13 +342,13 @@ impl StorageLiveLocals {
348342
) -> StorageLiveLocals {
349343
let mut storage_live = IndexVec::from_elem(Set1::Empty, &body.local_decls);
350344
for local in always_storage_live_locals.iter() {
351-
storage_live[local] = Set1::One(LocationExtended::Arg);
345+
storage_live[local] = Set1::One(DefLocation::Argument);
352346
}
353347
for (block, bbdata) in body.basic_blocks.iter_enumerated() {
354348
for (statement_index, statement) in bbdata.statements.iter().enumerate() {
355349
if let StatementKind::StorageLive(local) = statement.kind {
356350
storage_live[local]
357-
.insert(LocationExtended::Plain(Location { block, statement_index }));
351+
.insert(DefLocation::Body(Location { block, statement_index }));
358352
}
359353
}
360354
}

0 commit comments

Comments
 (0)