Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove clone() when removing extra stack operations #1078

Merged
merged 6 commits into from
Aug 23, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/optimize/stack2reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {

// Replace all unused stack_addr and stack_load instructions with nop.
for stack_slot_users in opt_ctx.stack_slot_usage_map.values_mut() {
// FIXME remove clone
// FIXME: Remove clone
for &inst in stack_slot_users.stack_addr.clone().iter() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use drain_filter with |inst| stack_addr_load_insts_users.get(inst).map(|users| users.is_empty()).unwrap_or(true) as argument and then remove the self.stack_addr.remove(inst) from remove_unused_stack_addr and remove the self param of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a very good idea and it set me on the correct path. Thanks

if stack_addr_load_insts_users.get(&inst).map(|users| users.is_empty()).unwrap_or(true) {
stack_slot_users.remove_unused_stack_addr(&mut opt_ctx.ctx.func, inst);
Expand Down