From 7087c8d7e7419210dfca9fb6e7ec2718725416a9 Mon Sep 17 00:00:00 2001 From: Tom French Date: Mon, 13 Jan 2025 13:44:54 +0000 Subject: [PATCH] feat: add more lazy removal of instructions with `Instruction::noop` --- compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs | 7 ++----- compiler/noirc_evaluator/src/ssa/opt/rc.rs | 14 +++----------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs index 96a24583837..4bf01844b56 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs @@ -592,11 +592,8 @@ impl<'f> PerFunctionContext<'f> { /// This is expected to contain any loads which were replaced and any stores which are /// no longer needed. fn remove_instructions(&mut self) { - // The order we iterate blocks in is not important - for block in self.post_order.as_slice() { - self.inserter.function.dfg[*block] - .instructions_mut() - .retain(|instruction| !self.instructions_to_remove.contains(instruction)); + for instruction in &self.instructions_to_remove { + self.inserter.function.dfg.remove_instruction(*instruction); } } diff --git a/compiler/noirc_evaluator/src/ssa/opt/rc.rs b/compiler/noirc_evaluator/src/ssa/opt/rc.rs index e25ad350145..86aa9840542 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/rc.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/rc.rs @@ -64,7 +64,9 @@ impl Function { context.find_rcs_in_entry_block(self); context.scan_for_array_sets(self); let to_remove = context.find_rcs_to_remove(self); - remove_instructions(to_remove, self); + for instruction in to_remove { + self.dfg.remove_instruction(instruction); + } } } @@ -141,16 +143,6 @@ pub(crate) fn pop_rc_for( Some(rcs.remove(position)) } -fn remove_instructions(to_remove: HashSet, function: &mut Function) { - if !to_remove.is_empty() { - for block in function.reachable_blocks() { - function.dfg[block] - .instructions_mut() - .retain(|instruction| !to_remove.contains(instruction)); - } - } -} - #[cfg(test)] mod test { use std::sync::Arc;