mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-18 00:18:47 +00:00
HW3 (3)
This commit is contained in:
@@ -136,6 +136,8 @@ impl Optimize<FunctionDefinition> for SimplifyCfgMerge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code.blocks.retain(|bid, _| !merged_to.contains_key(bid));
|
||||||
|
|
||||||
for (bid, block) in &mut code.blocks {
|
for (bid, block) in &mut code.blocks {
|
||||||
for inst in block.instructions.iter_mut() {
|
for inst in block.instructions.iter_mut() {
|
||||||
replace_instruction_operands(inst, &replaces);
|
replace_instruction_operands(inst, &replaces);
|
||||||
@@ -143,7 +145,6 @@ impl Optimize<FunctionDefinition> for SimplifyCfgMerge {
|
|||||||
replace_exit_operands(&mut block.exit, &replaces);
|
replace_exit_operands(&mut block.exit, &replaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
code.blocks.retain(|bid, _| !merged_to.contains_key(bid));
|
|
||||||
!merged_to.is_empty()
|
!merged_to.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,25 +291,19 @@ fn replace_instruction_operands(inst: &mut Instruction, replaces: &HashMap<Regis
|
|||||||
replace_operand(lhs, replaces);
|
replace_operand(lhs, replaces);
|
||||||
replace_operand(rhs, replaces);
|
replace_operand(rhs, replaces);
|
||||||
}
|
}
|
||||||
Instruction::UnaryOp { operand, .. } => {
|
Instruction::UnaryOp { operand, .. } => replace_operand(operand, replaces),
|
||||||
replace_operand(operand, replaces);
|
|
||||||
}
|
|
||||||
Instruction::Store { ptr, value } => {
|
Instruction::Store { ptr, value } => {
|
||||||
replace_operand(ptr, replaces);
|
replace_operand(ptr, replaces);
|
||||||
replace_operand(value, replaces);
|
replace_operand(value, replaces);
|
||||||
}
|
}
|
||||||
Instruction::Load { ptr } => {
|
Instruction::Load { ptr } => replace_operand(ptr, replaces),
|
||||||
replace_operand(ptr, replaces);
|
|
||||||
}
|
|
||||||
Instruction::Call { callee, args, .. } => {
|
Instruction::Call { callee, args, .. } => {
|
||||||
replace_operand(callee, replaces);
|
replace_operand(callee, replaces);
|
||||||
for arg in args.iter_mut() {
|
for arg in args.iter_mut() {
|
||||||
replace_operand(arg, replaces);
|
replace_operand(arg, replaces);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Instruction::TypeCast { value, .. } => {
|
Instruction::TypeCast { value, .. } => replace_operand(value, replaces),
|
||||||
replace_operand(value, replaces);
|
|
||||||
}
|
|
||||||
Instruction::GetElementPtr { ptr, offset, .. } => {
|
Instruction::GetElementPtr { ptr, offset, .. } => {
|
||||||
replace_operand(ptr, replaces);
|
replace_operand(ptr, replaces);
|
||||||
replace_operand(offset, replaces);
|
replace_operand(offset, replaces);
|
||||||
|
|||||||
Reference in New Issue
Block a user