@@ -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,14 +94,7 @@ 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) ) => {
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) ,
105
98
_ => false ,
106
99
}
107
100
}
@@ -111,7 +104,7 @@ impl SsaLocals {
111
104
body : & ' a Body < ' tcx > ,
112
105
) -> impl Iterator < Item = ( Local , & ' a Rvalue < ' tcx > , Location ) > + ' a {
113
106
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] {
115
108
// `loc` must point to a direct assignment to `local`.
116
109
let Either :: Left ( stmt) = body. stmt_at ( loc) else { bug ! ( ) } ;
117
110
let Some ( ( target, rvalue) ) = stmt. kind . as_assign ( ) else { bug ! ( ) } ;
@@ -129,7 +122,7 @@ impl SsaLocals {
129
122
mut f : impl FnMut ( Local , & mut Rvalue < ' tcx > , Location ) ,
130
123
) {
131
124
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] {
133
126
// `loc` must point to a direct assignment to `local`.
134
127
let bbs = basic_blocks. as_mut_preserves_cfg ( ) ;
135
128
let bb = & mut bbs[ loc. block ] ;
@@ -187,15 +180,9 @@ impl SsaLocals {
187
180
}
188
181
}
189
182
190
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
191
- enum LocationExtended {
192
- Plain ( Location ) ,
193
- Arg ,
194
- }
195
-
196
183
struct SsaVisitor < ' a > {
197
184
dominators : & ' a Dominators < BasicBlock > ,
198
- assignments : IndexVec < Local , Set1 < LocationExtended > > ,
185
+ assignments : IndexVec < Local , Set1 < DefLocation > > ,
199
186
assignment_order : Vec < Local > ,
200
187
direct_uses : IndexVec < Local , u32 > ,
201
188
}
@@ -205,10 +192,7 @@ impl SsaVisitor<'_> {
205
192
let set = & mut self . assignments [ local] ;
206
193
let assign_dominates = match * set {
207
194
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 ) ,
212
196
} ;
213
197
// We are visiting a use that is not dominated by an assignment.
214
198
// Either there is a cycle involved, or we are reading for uninitialized local.
@@ -262,7 +246,7 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
262
246
263
247
fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , loc : Location ) {
264
248
if let Some ( local) = place. as_local ( ) {
265
- self . assignments [ local] . insert ( LocationExtended :: Plain ( loc) ) ;
249
+ self . assignments [ local] . insert ( DefLocation :: Body ( loc) ) ;
266
250
if let Set1 :: One ( _) = self . assignments [ local] {
267
251
// Only record if SSA-like, to avoid growing the vector needlessly.
268
252
self . assignment_order . push ( local) ;
@@ -338,7 +322,7 @@ fn compute_copy_classes(ssa: &mut SsaLocals, body: &Body<'_>) {
338
322
#[ derive( Debug ) ]
339
323
pub ( crate ) struct StorageLiveLocals {
340
324
/// Set of "StorageLive" statements for each local.
341
- storage_live : IndexVec < Local , Set1 < LocationExtended > > ,
325
+ storage_live : IndexVec < Local , Set1 < DefLocation > > ,
342
326
}
343
327
344
328
impl StorageLiveLocals {
@@ -348,13 +332,13 @@ impl StorageLiveLocals {
348
332
) -> StorageLiveLocals {
349
333
let mut storage_live = IndexVec :: from_elem ( Set1 :: Empty , & body. local_decls ) ;
350
334
for local in always_storage_live_locals. iter ( ) {
351
- storage_live[ local] = Set1 :: One ( LocationExtended :: Arg ) ;
335
+ storage_live[ local] = Set1 :: One ( DefLocation :: Argument ) ;
352
336
}
353
337
for ( block, bbdata) in body. basic_blocks . iter_enumerated ( ) {
354
338
for ( statement_index, statement) in bbdata. statements . iter ( ) . enumerate ( ) {
355
339
if let StatementKind :: StorageLive ( local) = statement. kind {
356
340
storage_live[ local]
357
- . insert ( LocationExtended :: Plain ( Location { block, statement_index } ) ) ;
341
+ . insert ( DefLocation :: Body ( Location { block, statement_index } ) ) ;
358
342
}
359
343
}
360
344
}
0 commit comments