@@ -61,7 +61,7 @@ pub enum ArgPointeeMutability {
61
61
NotAPointer ,
62
62
}
63
63
64
- // The dominator tree is represented by mapping each Block to its DomTreeNode .
64
+ /// Result of the arg pointee mutability analysis, for the arguments of each function .
65
65
#[ derive( Default ) ]
66
66
pub struct ArgPointeeMutabilityResult ( FxHashMap < Function , Vec < ArgPointeeMutability > > ) ;
67
67
@@ -168,12 +168,14 @@ fn analyse_fn(
168
168
}
169
169
// Known aliases of this argument. Also serves as a visited set.
170
170
let mut aliases: FxHashSet < Value > = FxHashSet :: default ( ) ;
171
- let mut worklist = FxHashSet :: default ( ) ;
171
+ let mut in_worklist = FxHashSet :: default ( ) ;
172
+ let mut worklist = vec ! [ ] ;
172
173
// Start with the argument value itself.
173
- worklist. insert ( * arg) ;
174
+ in_worklist. insert ( * arg) ;
175
+ worklist. push ( * arg) ;
174
176
175
- while let Some ( value) = worklist. iter ( ) . next ( ) . cloned ( ) {
176
- worklist . remove ( & value) ;
177
+ while let Some ( value) = worklist. pop ( ) {
178
+ in_worklist . remove ( & value) ;
177
179
if !aliases. insert ( value) {
178
180
// If we already visited this value, skip it.
179
181
continue ;
@@ -210,7 +212,8 @@ fn analyse_fn(
210
212
. unwrap_or_default ( )
211
213
. iter ( )
212
214
. for_each ( |r#use| {
213
- worklist. insert ( * r#use) ;
215
+ in_worklist. insert ( * r#use) ;
216
+ worklist. push ( * r#use) ;
214
217
} ) ;
215
218
}
216
219
BinaryOpKind :: Mul
@@ -241,7 +244,8 @@ fn analyse_fn(
241
244
. unwrap_or_default ( )
242
245
. iter ( )
243
246
. for_each ( |r#use| {
244
- worklist. insert ( * r#use) ;
247
+ in_worklist. insert ( * r#use) ;
248
+ worklist. push ( * r#use) ;
245
249
} ) ;
246
250
}
247
251
InstOp :: Load ( _) => {
@@ -255,7 +259,7 @@ fn analyse_fn(
255
259
// then the argument is being mutated. (We could be here
256
260
// because the source pointer is a use of the argument pointer,
257
261
// but that doesn't indicate mutability).
258
- if worklist . contains ( dst_val_ptr) || aliases. contains ( dst_val_ptr) {
262
+ if in_worklist . contains ( dst_val_ptr) || aliases. contains ( dst_val_ptr) {
259
263
// If the destination pointer is the same as the argument pointer,
260
264
// we can assume that the pointee is mutable.
261
265
* arg_mutabilities. get_mut ( arg_idx) . unwrap ( ) =
@@ -276,7 +280,8 @@ fn analyse_fn(
276
280
// The callee mutates the parameter at caller_param_idx
277
281
// If what we're passing at that position is an alias of our argument,
278
282
// then we mark that our argument is mutable.
279
- if worklist. contains ( caller_param) || aliases. contains ( caller_param)
283
+ if in_worklist. contains ( caller_param)
284
+ || aliases. contains ( caller_param)
280
285
{
281
286
* arg_mutabilities. get_mut ( arg_idx) . unwrap ( ) =
282
287
ArgPointeeMutability :: Mutable ;
@@ -295,7 +300,7 @@ fn analyse_fn(
295
300
FuelVmInstruction :: StateLoadQuadWord { load_val, .. } => {
296
301
// If the loaded value is an alias of the argument pointer,
297
302
// then the argument is being mutated.
298
- if worklist . contains ( load_val) || aliases. contains ( load_val) {
303
+ if in_worklist . contains ( load_val) || aliases. contains ( load_val) {
299
304
* arg_mutabilities. get_mut ( arg_idx) . unwrap ( ) =
300
305
ArgPointeeMutability :: Mutable ;
301
306
continue ' analyse_next_arg;
@@ -309,7 +314,7 @@ fn analyse_fn(
309
314
| FuelVmInstruction :: WideModularOp { result, .. } => {
310
315
// If the result is an alias of the argument pointer,
311
316
// then the argument is being mutated.
312
- if worklist . contains ( result) || aliases. contains ( result) {
317
+ if in_worklist . contains ( result) || aliases. contains ( result) {
313
318
* arg_mutabilities. get_mut ( arg_idx) . unwrap ( ) =
314
319
ArgPointeeMutability :: Mutable ;
315
320
continue ' analyse_next_arg;
@@ -327,7 +332,8 @@ fn analyse_fn(
327
332
. unwrap_or_default ( )
328
333
. iter ( )
329
334
. for_each ( |r#use| {
330
- worklist. insert ( * r#use) ;
335
+ in_worklist. insert ( * r#use) ;
336
+ worklist. push ( * r#use) ;
331
337
} ) ;
332
338
}
333
339
ValueDatum :: Constant ( _) => panic ! ( "Constants cannot be users" ) ,
@@ -337,12 +343,5 @@ fn analyse_fn(
337
343
338
344
res. 0 . insert ( function, arg_mutabilities) ;
339
345
340
- // crate::function_print(ctx, function);
341
- // println!(
342
- // "Function {}: arg_mutabilities: {:?}",
343
- // function.get_name(ctx),
344
- // res.0.get(&function).unwrap()
345
- // );
346
-
347
346
Ok ( ( ) )
348
347
}
0 commit comments