@@ -15,7 +15,7 @@ use rustc_middle::mir::*;
15
15
16
16
pub struct SsaLocals {
17
17
/// Assignments to each local. This defines whether the local is SSA.
18
- assignments : IndexVec < Local , Set1 < LocationExtended > > ,
18
+ assignments : IndexVec < Local , Set1 < DefLocation > > ,
19
19
/// We visit the body in reverse postorder, to ensure each local is assigned before it is used.
20
20
/// We remember the order in which we saw the assignments to compute the SSA values in a single
21
21
/// pass.
@@ -38,7 +38,7 @@ impl SsaLocals {
38
38
let mut visitor = SsaVisitor { assignments, assignment_order, dominators, direct_uses } ;
39
39
40
40
for local in body. args_iter ( ) {
41
- visitor. assignments [ local] = Set1 :: One ( LocationExtended :: Arg ) ;
41
+ visitor. assignments [ local] = Set1 :: One ( DefLocation :: Argument ) ;
42
42
}
43
43
44
44
// For SSA assignments, a RPO visit will see the assignment before it sees any use.
@@ -94,8 +94,8 @@ impl SsaLocals {
94
94
location : Location ,
95
95
) -> bool {
96
96
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) ) => {
99
99
if ass. block == location. block {
100
100
ass. statement_index < location. statement_index
101
101
} else {
@@ -111,7 +111,7 @@ impl SsaLocals {
111
111
body : & ' a Body < ' tcx > ,
112
112
) -> impl Iterator < Item = ( Local , & ' a Rvalue < ' tcx > , Location ) > + ' a {
113
113
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] {
115
115
// `loc` must point to a direct assignment to `local`.
116
116
let Either :: Left ( stmt) = body. stmt_at ( loc) else { bug ! ( ) } ;
117
117
let Some ( ( target, rvalue) ) = stmt. kind . as_assign ( ) else { bug ! ( ) } ;
@@ -129,7 +129,7 @@ impl SsaLocals {
129
129
mut f : impl FnMut ( Local , & mut Rvalue < ' tcx > , Location ) ,
130
130
) {
131
131
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] {
133
133
// `loc` must point to a direct assignment to `local`.
134
134
let bbs = basic_blocks. as_mut_preserves_cfg ( ) ;
135
135
let bb = & mut bbs[ loc. block ] ;
@@ -187,15 +187,9 @@ impl SsaLocals {
187
187
}
188
188
}
189
189
190
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
191
- enum LocationExtended {
192
- Plain ( Location ) ,
193
- Arg ,
194
- }
195
-
196
190
struct SsaVisitor < ' a > {
197
191
dominators : & ' a Dominators < BasicBlock > ,
198
- assignments : IndexVec < Local , Set1 < LocationExtended > > ,
192
+ assignments : IndexVec < Local , Set1 < DefLocation > > ,
199
193
assignment_order : Vec < Local > ,
200
194
direct_uses : IndexVec < Local , u32 > ,
201
195
}
@@ -205,8 +199,8 @@ impl SsaVisitor<'_> {
205
199
let set = & mut self . assignments [ local] ;
206
200
let assign_dominates = match * set {
207
201
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) ) => {
210
204
assign. successor_within_block ( ) . dominates ( loc, self . dominators )
211
205
}
212
206
} ;
@@ -262,7 +256,7 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
262
256
263
257
fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , loc : Location ) {
264
258
if let Some ( local) = place. as_local ( ) {
265
- self . assignments [ local] . insert ( LocationExtended :: Plain ( loc) ) ;
259
+ self . assignments [ local] . insert ( DefLocation :: Body ( loc) ) ;
266
260
if let Set1 :: One ( _) = self . assignments [ local] {
267
261
// Only record if SSA-like, to avoid growing the vector needlessly.
268
262
self . assignment_order . push ( local) ;
@@ -338,7 +332,7 @@ fn compute_copy_classes(ssa: &mut SsaLocals, body: &Body<'_>) {
338
332
#[ derive( Debug ) ]
339
333
pub ( crate ) struct StorageLiveLocals {
340
334
/// Set of "StorageLive" statements for each local.
341
- storage_live : IndexVec < Local , Set1 < LocationExtended > > ,
335
+ storage_live : IndexVec < Local , Set1 < DefLocation > > ,
342
336
}
343
337
344
338
impl StorageLiveLocals {
@@ -348,13 +342,13 @@ impl StorageLiveLocals {
348
342
) -> StorageLiveLocals {
349
343
let mut storage_live = IndexVec :: from_elem ( Set1 :: Empty , & body. local_decls ) ;
350
344
for local in always_storage_live_locals. iter ( ) {
351
- storage_live[ local] = Set1 :: One ( LocationExtended :: Arg ) ;
345
+ storage_live[ local] = Set1 :: One ( DefLocation :: Argument ) ;
352
346
}
353
347
for ( block, bbdata) in body. basic_blocks . iter_enumerated ( ) {
354
348
for ( statement_index, statement) in bbdata. statements . iter ( ) . enumerate ( ) {
355
349
if let StatementKind :: StorageLive ( local) = statement. kind {
356
350
storage_live[ local]
357
- . insert ( LocationExtended :: Plain ( Location { block, statement_index } ) ) ;
351
+ . insert ( DefLocation :: Body ( Location { block, statement_index } ) ) ;
358
352
}
359
353
}
360
354
}
0 commit comments