@@ -180,8 +180,18 @@ impl LivenessResult {
180
180
block,
181
181
statement_index,
182
182
} ;
183
- let terminator_defs_uses = self . defs_uses ( mir, terminator_location, & data. terminator ) ;
184
- terminator_defs_uses. apply ( & mut bits) ;
183
+ let locals = mir. local_decls . len ( ) ;
184
+ let mut visitor = DefsUsesVisitor {
185
+ mode : self . mode ,
186
+ defs_uses : DefsUses {
187
+ defs : LocalSet :: new_empty ( locals) ,
188
+ uses : LocalSet :: new_empty ( locals) ,
189
+ } ,
190
+ } ;
191
+ // Visit the various parts of the basic block in reverse. If we go
192
+ // forward, the logic in `add_def` and `add_use` would be wrong.
193
+ data. terminator . apply ( terminator_location, & mut visitor) ;
194
+ visitor. defs_uses . apply ( & mut bits) ;
185
195
callback ( terminator_location, & bits) ;
186
196
187
197
// Compute liveness before each statement (in rev order) and invoke callback.
@@ -191,33 +201,14 @@ impl LivenessResult {
191
201
block,
192
202
statement_index,
193
203
} ;
194
- let statement_defs_uses = self . defs_uses ( mir, statement_location, statement) ;
195
- statement_defs_uses. apply ( & mut bits) ;
204
+ visitor. defs_uses . clear ( ) ;
205
+ statement. apply ( statement_location, & mut visitor) ;
206
+ visitor. defs_uses . apply ( & mut bits) ;
196
207
callback ( statement_location, & bits) ;
197
208
}
198
209
199
210
assert_eq ! ( bits, self . ins[ block] ) ;
200
211
}
201
-
202
- fn defs_uses < ' tcx , V > ( & self , mir : & Mir < ' tcx > , location : Location , thing : & V ) -> DefsUses
203
- where
204
- V : MirVisitable < ' tcx > ,
205
- {
206
- let locals = mir. local_decls . len ( ) ;
207
- let mut visitor = DefsUsesVisitor {
208
- mode : self . mode ,
209
- defs_uses : DefsUses {
210
- defs : LocalSet :: new_empty ( locals) ,
211
- uses : LocalSet :: new_empty ( locals) ,
212
- } ,
213
- } ;
214
-
215
- // Visit the various parts of the basic block in reverse. If we go
216
- // forward, the logic in `add_def` and `add_use` would be wrong.
217
- thing. apply ( location, & mut visitor) ;
218
-
219
- visitor. defs_uses
220
- }
221
212
}
222
213
223
214
#[ derive( Eq , PartialEq , Clone ) ]
@@ -307,6 +298,11 @@ struct DefsUses {
307
298
}
308
299
309
300
impl DefsUses {
301
+ fn clear ( & mut self ) {
302
+ self . uses . clear ( ) ;
303
+ self . defs . clear ( ) ;
304
+ }
305
+
310
306
fn apply ( & self , bits : & mut LocalSet ) -> bool {
311
307
bits. subtract ( & self . defs ) | bits. union ( & self . uses )
312
308
}
0 commit comments