Skip to content

Commit 44abfd4

Browse files
committed
address review comments
1 parent a3d6cc6 commit 44abfd4

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

sway-ir/src/optimize/arg_mutability_tagger.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub enum ArgPointeeMutability {
6161
NotAPointer,
6262
}
6363

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.
6565
#[derive(Default)]
6666
pub struct ArgPointeeMutabilityResult(FxHashMap<Function, Vec<ArgPointeeMutability>>);
6767

@@ -168,12 +168,14 @@ fn analyse_fn(
168168
}
169169
// Known aliases of this argument. Also serves as a visited set.
170170
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![];
172173
// Start with the argument value itself.
173-
worklist.insert(*arg);
174+
in_worklist.insert(*arg);
175+
worklist.push(*arg);
174176

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);
177179
if !aliases.insert(value) {
178180
// If we already visited this value, skip it.
179181
continue;
@@ -210,7 +212,8 @@ fn analyse_fn(
210212
.unwrap_or_default()
211213
.iter()
212214
.for_each(|r#use| {
213-
worklist.insert(*r#use);
215+
in_worklist.insert(*r#use);
216+
worklist.push(*r#use);
214217
});
215218
}
216219
BinaryOpKind::Mul
@@ -241,7 +244,8 @@ fn analyse_fn(
241244
.unwrap_or_default()
242245
.iter()
243246
.for_each(|r#use| {
244-
worklist.insert(*r#use);
247+
in_worklist.insert(*r#use);
248+
worklist.push(*r#use);
245249
});
246250
}
247251
InstOp::Load(_) => {
@@ -255,7 +259,7 @@ fn analyse_fn(
255259
// then the argument is being mutated. (We could be here
256260
// because the source pointer is a use of the argument pointer,
257261
// 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) {
259263
// If the destination pointer is the same as the argument pointer,
260264
// we can assume that the pointee is mutable.
261265
*arg_mutabilities.get_mut(arg_idx).unwrap() =
@@ -276,7 +280,8 @@ fn analyse_fn(
276280
// The callee mutates the parameter at caller_param_idx
277281
// If what we're passing at that position is an alias of our argument,
278282
// 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)
280285
{
281286
*arg_mutabilities.get_mut(arg_idx).unwrap() =
282287
ArgPointeeMutability::Mutable;
@@ -295,7 +300,7 @@ fn analyse_fn(
295300
FuelVmInstruction::StateLoadQuadWord { load_val, .. } => {
296301
// If the loaded value is an alias of the argument pointer,
297302
// 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) {
299304
*arg_mutabilities.get_mut(arg_idx).unwrap() =
300305
ArgPointeeMutability::Mutable;
301306
continue 'analyse_next_arg;
@@ -309,7 +314,7 @@ fn analyse_fn(
309314
| FuelVmInstruction::WideModularOp { result, .. } => {
310315
// If the result is an alias of the argument pointer,
311316
// then the argument is being mutated.
312-
if worklist.contains(result) || aliases.contains(result) {
317+
if in_worklist.contains(result) || aliases.contains(result) {
313318
*arg_mutabilities.get_mut(arg_idx).unwrap() =
314319
ArgPointeeMutability::Mutable;
315320
continue 'analyse_next_arg;
@@ -327,7 +332,8 @@ fn analyse_fn(
327332
.unwrap_or_default()
328333
.iter()
329334
.for_each(|r#use| {
330-
worklist.insert(*r#use);
335+
in_worklist.insert(*r#use);
336+
worklist.push(*r#use);
331337
});
332338
}
333339
ValueDatum::Constant(_) => panic!("Constants cannot be users"),
@@ -337,12 +343,5 @@ fn analyse_fn(
337343

338344
res.0.insert(function, arg_mutabilities);
339345

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-
347346
Ok(())
348347
}

sway-ir/src/optimize/memcpyopt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn local_copy_prop(
577577
Either::Right(*arg)
578578
}
579579
});
580-
// whichever args may get mutabed, we kill them.
580+
// whichever args may get mutated, we kill them.
581581
kill_escape_args(
582582
context,
583583
&mutable_args,

0 commit comments

Comments
 (0)