From 41f68116cb3441709928a54f3bb7bd28802b856f Mon Sep 17 00:00:00 2001 From: static Date: Thu, 8 May 2025 10:19:04 +0000 Subject: [PATCH] HW3 (3) --- src/opt/simplify_cfg.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/opt/simplify_cfg.rs b/src/opt/simplify_cfg.rs index 6f4be0c..a3764c9 100644 --- a/src/opt/simplify_cfg.rs +++ b/src/opt/simplify_cfg.rs @@ -136,6 +136,8 @@ impl Optimize for SimplifyCfgMerge { } } + code.blocks.retain(|bid, _| !merged_to.contains_key(bid)); + for (bid, block) in &mut code.blocks { for inst in block.instructions.iter_mut() { replace_instruction_operands(inst, &replaces); @@ -143,7 +145,6 @@ impl Optimize for SimplifyCfgMerge { replace_exit_operands(&mut block.exit, &replaces); } - code.blocks.retain(|bid, _| !merged_to.contains_key(bid)); !merged_to.is_empty() } } @@ -290,25 +291,19 @@ fn replace_instruction_operands(inst: &mut Instruction, replaces: &HashMap { - replace_operand(operand, replaces); - } + Instruction::UnaryOp { operand, .. } => replace_operand(operand, replaces), Instruction::Store { ptr, value } => { replace_operand(ptr, replaces); replace_operand(value, replaces); } - Instruction::Load { ptr } => { - replace_operand(ptr, replaces); - } + Instruction::Load { ptr } => replace_operand(ptr, replaces), Instruction::Call { callee, args, .. } => { replace_operand(callee, replaces); for arg in args.iter_mut() { replace_operand(arg, replaces); } } - Instruction::TypeCast { value, .. } => { - replace_operand(value, replaces); - } + Instruction::TypeCast { value, .. } => replace_operand(value, replaces), Instruction::GetElementPtr { ptr, offset, .. } => { replace_operand(ptr, replaces); replace_operand(offset, replaces);