4
4
use rustc_index:: bit_set:: BitSet ;
5
5
use rustc_data_structures:: graph:: dominators:: Dominators ;
6
6
use rustc_index:: vec:: { Idx , IndexVec } ;
7
- use rustc:: mir:: { self , Body , BodyCache , Location , TerminatorKind } ;
7
+ use rustc:: mir:: { self , BasicBlock , Body , BodyCache , Location , TerminatorKind } ;
8
8
use rustc:: mir:: visit:: {
9
9
Visitor , PlaceContext , MutatingUseContext , NonMutatingUseContext , NonUseContext ,
10
10
} ;
@@ -16,11 +16,12 @@ use syntax_pos::DUMMY_SP;
16
16
use super :: FunctionCx ;
17
17
use crate :: traits:: * ;
18
18
19
- pub fn non_ssa_locals < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
19
+ pub fn non_ssa_locals < ' b , ' a : ' b , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
20
20
fx : & mut FunctionCx < ' a , ' tcx , Bx > ,
21
+ mir : & ' b mut BodyCache < & ' a Body < ' tcx > > ,
21
22
) -> BitSet < mir:: Local > {
22
- let mir = fx . mir . take ( ) . unwrap ( ) ;
23
- let mut analyzer = LocalAnalyzer :: new ( fx, mir) ;
23
+ let dominators = mir. dominators ( ) ;
24
+ let mut analyzer = LocalAnalyzer :: new ( fx, mir, dominators ) ;
24
25
25
26
analyzer. visit_body ( mir) ;
26
27
@@ -54,29 +55,27 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
54
55
}
55
56
}
56
57
57
- let ( mir, non_ssa_locals) = analyzer. finalize ( ) ;
58
- fx. mir = Some ( mir) ;
59
- non_ssa_locals
58
+ analyzer. non_ssa_locals
60
59
}
61
60
62
- struct LocalAnalyzer < ' mir , ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > {
61
+ struct LocalAnalyzer < ' mir , ' a , ' b , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > {
63
62
fx : & ' mir FunctionCx < ' a , ' tcx , Bx > ,
64
- mir : & ' a mut BodyCache < & ' a Body < ' tcx > > ,
63
+ mir : & ' b Body < ' tcx > ,
65
64
dominators : Dominators < mir:: BasicBlock > ,
66
65
non_ssa_locals : BitSet < mir:: Local > ,
67
66
// The location of the first visited direct assignment to each
68
67
// local, or an invalid location (out of bounds `block` index).
69
68
first_assignment : IndexVec < mir:: Local , Location > ,
70
69
}
71
70
72
- impl < Bx : BuilderMethods < ' a , ' tcx > > LocalAnalyzer < ' mir , ' a , ' tcx , Bx > {
73
- fn new ( fx : & ' mir FunctionCx < ' a , ' tcx , Bx > , mir : & ' a mut BodyCache < & ' a Body < ' tcx > > ) -> Self {
71
+ impl < ' mir , ' a , ' b , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > LocalAnalyzer < ' mir , ' a , ' b , ' tcx , Bx > {
72
+ fn new ( fx : & ' mir FunctionCx < ' a , ' tcx , Bx > , mir : & ' b Body < ' tcx > , dominators : Dominators < BasicBlock > ) -> Self {
74
73
let invalid_location =
75
74
mir:: BasicBlock :: new ( mir. basic_blocks ( ) . len ( ) ) . start_location ( ) ;
76
75
let mut analyzer = LocalAnalyzer {
77
76
fx,
78
- dominators : mir. dominators ( ) ,
79
77
mir,
78
+ dominators,
80
79
non_ssa_locals : BitSet :: new_empty ( mir. local_decls . len ( ) ) ,
81
80
first_assignment : IndexVec :: from_elem ( invalid_location, & mir. local_decls )
82
81
} ;
@@ -89,10 +88,6 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
89
88
analyzer
90
89
}
91
90
92
- fn finalize ( self ) -> ( & ' a mut BodyCache < & ' a Body < ' tcx > > , BitSet < mir:: Local > ) {
93
- ( self . mir , self . non_ssa_locals )
94
- }
95
-
96
91
fn first_assignment ( & self , local : mir:: Local ) -> Option < Location > {
97
92
let location = self . first_assignment [ local] ;
98
93
if location. block . index ( ) < self . mir . basic_blocks ( ) . len ( ) {
@@ -138,7 +133,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
138
133
} ;
139
134
if is_consume {
140
135
let base_ty =
141
- mir:: Place :: ty_from ( place_ref. base , proj_base, self . mir . body ( ) , cx. tcx ( ) ) ;
136
+ mir:: Place :: ty_from ( place_ref. base , proj_base, self . mir , cx. tcx ( ) ) ;
142
137
let base_ty = self . fx . monomorphize ( & base_ty) ;
143
138
144
139
// ZSTs don't require any actual memory access.
@@ -240,8 +235,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
240
235
241
236
}
242
237
243
- impl < ' mir , ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > Visitor < ' tcx >
244
- for LocalAnalyzer < ' mir , ' a , ' tcx , Bx >
238
+ impl < ' mir , ' a , ' b , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > Visitor < ' tcx >
239
+ for LocalAnalyzer < ' mir , ' a , ' b , ' tcx , Bx >
245
240
{
246
241
fn visit_assign ( & mut self ,
247
242
place : & mir:: Place < ' tcx > ,
@@ -252,7 +247,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
252
247
if let Some ( index) = place. as_local ( ) {
253
248
self . assign ( index, location) ;
254
249
let decl_span = self . mir . local_decls [ index] . source_info . span ;
255
- if !self . fx . rvalue_creates_operand ( rvalue, decl_span) {
250
+ if !self . fx . rvalue_creates_operand ( rvalue, decl_span, self . mir ) {
256
251
self . not_ssa ( index) ;
257
252
}
258
253
} else {
0 commit comments