@@ -36,7 +36,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
36
36
37
37
// Arguments get assigned to by means of the function being called
38
38
for arg in mir. args_iter ( ) {
39
- analyzer. assign ( arg, mir :: START_BLOCK . start_location ( ) ) ;
39
+ analyzer. assign ( arg, DefLocation :: Argument ) ;
40
40
}
41
41
42
42
// If there exists a local definition that dominates all uses of that local,
@@ -64,7 +64,22 @@ enum LocalKind {
64
64
/// A scalar or a scalar pair local that is neither defined nor used.
65
65
Unused ,
66
66
/// A scalar or a scalar pair local with a single definition that dominates all uses.
67
- SSA ( mir:: Location ) ,
67
+ SSA ( DefLocation ) ,
68
+ }
69
+
70
+ #[ derive( Copy , Clone , PartialEq , Eq ) ]
71
+ enum DefLocation {
72
+ Argument ,
73
+ Body ( Location ) ,
74
+ }
75
+
76
+ impl DefLocation {
77
+ fn dominates ( self , location : Location , dominators : & Dominators < mir:: BasicBlock > ) -> bool {
78
+ match self {
79
+ DefLocation :: Argument => true ,
80
+ DefLocation :: Body ( def) => def. successor_within_block ( ) . dominates ( location, dominators) ,
81
+ }
82
+ }
68
83
}
69
84
70
85
struct LocalAnalyzer < ' mir , ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > {
@@ -74,17 +89,13 @@ struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
74
89
}
75
90
76
91
impl < ' mir , ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > LocalAnalyzer < ' mir , ' a , ' tcx , Bx > {
77
- fn assign ( & mut self , local : mir:: Local , location : Location ) {
92
+ fn assign ( & mut self , local : mir:: Local , location : DefLocation ) {
78
93
let kind = & mut self . locals [ local] ;
79
94
match * kind {
80
95
LocalKind :: ZST => { }
81
96
LocalKind :: Memory => { }
82
- LocalKind :: Unused => {
83
- * kind = LocalKind :: SSA ( location) ;
84
- }
85
- LocalKind :: SSA ( _) => {
86
- * kind = LocalKind :: Memory ;
87
- }
97
+ LocalKind :: Unused => * kind = LocalKind :: SSA ( location) ,
98
+ LocalKind :: SSA ( _) => * kind = LocalKind :: Memory ,
88
99
}
89
100
}
90
101
@@ -166,7 +177,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
166
177
debug ! ( "visit_assign(place={:?}, rvalue={:?})" , place, rvalue) ;
167
178
168
179
if let Some ( local) = place. as_local ( ) {
169
- self . assign ( local, location) ;
180
+ self . assign ( local, DefLocation :: Body ( location) ) ;
170
181
if self . locals [ local] != LocalKind :: Memory {
171
182
let decl_span = self . fx . mir . local_decls [ local] . source_info . span ;
172
183
if !self . fx . rvalue_creates_operand ( rvalue, decl_span) {
@@ -189,7 +200,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
189
200
match context {
190
201
PlaceContext :: MutatingUse ( MutatingUseContext :: Call )
191
202
| PlaceContext :: MutatingUse ( MutatingUseContext :: Yield ) => {
192
- self . assign ( local, location) ;
203
+ self . assign ( local, DefLocation :: Body ( location) ) ;
193
204
}
194
205
195
206
PlaceContext :: NonUse ( _) | PlaceContext :: MutatingUse ( MutatingUseContext :: Retag ) => { }
0 commit comments