Skip to content

Commit eb6df58

Browse files
committed
stack2reg: Remove clone() using filters
1 parent b0ea85f commit eb6df58

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/optimize/stack2reg.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,19 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {
312312
}
313313

314314
// Replace all unused stack_addr and stack_load instructions with nop.
315+
let mut func = &mut opt_ctx.ctx.func;
315316
for stack_slot_users in opt_ctx.stack_slot_usage_map.values_mut() {
316-
for &inst in stack_slot_users.stack_addr.clone().iter() {
317-
if stack_addr_load_insts_users.get(&inst).map(|users| users.is_empty()).unwrap_or(true) {
318-
StackSlotUsage::remove_unused_stack_addr(&mut opt_ctx.ctx.func, inst);
319-
stack_slot_users.stack_addr.remove(&inst);
320-
}
321-
}
322-
323-
/*
324-
for &inst in stack_slot_users.stack_load.clone().iter() {
325-
if stack_addr_load_insts_users.get(&inst).map(|users| users.is_empty()).unwrap_or(true) {
326-
StackSlotUsage::remove_unused_load(&mut opt_ctx.ctx.func, inst);
327-
stack_slot_users.stack_load.remove(&inst);
328-
}
329-
}
330-
*/
317+
stack_slot_users
318+
.stack_addr
319+
.iter()
320+
.filter(|inst| stack_addr_load_insts_users.get(inst).map(|users| users.is_empty()).unwrap_or(true))
321+
.for_each(|inst| StackSlotUsage::remove_unused_stack_addr(&mut func, *inst));
322+
323+
stack_slot_users
324+
.stack_load
325+
.iter()
326+
.filter(|inst| stack_addr_load_insts_users.get(inst).map(|users| users.is_empty()).unwrap_or(true))
327+
.for_each(|inst| StackSlotUsage::remove_unused_load(&mut func, *inst));
331328
}
332329
}
333330

0 commit comments

Comments
 (0)