From 9758834e5f8fa7eb83116a1c7579d0c2278d5ba8 Mon Sep 17 00:00:00 2001 From: Solo-steven Date: Tue, 24 Sep 2024 10:51:29 +0800 Subject: [PATCH] feat: add licm pass test case --- compilers/rustyc/optimizer/src/main.rs | 11 +++++--- .../rustyc/optimizer/tests/build_ir_graph.rs | 8 ++++-- .../tests/ir_optimizer_test_runner.rs | 28 +++++++++---------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/compilers/rustyc/optimizer/src/main.rs b/compilers/rustyc/optimizer/src/main.rs index 07baa60d..097f7915 100644 --- a/compilers/rustyc/optimizer/src/main.rs +++ b/compilers/rustyc/optimizer/src/main.rs @@ -165,7 +165,6 @@ fn main() { // anaylsiser_example(); } - pub fn create_licm_graph_simple_example_from_cmu() -> Function { let mut function = Function::new(String::from("test_fun")); // create blocks @@ -195,8 +194,12 @@ pub fn create_licm_graph_simple_example_from_cmu() -> Function { let a_inner = function.build_add_inst(b, c); let e = function.add_register(IrValueType::I16); function.insert_inst_to_block_front( - &b2, - ir::instructions::InstructionData::Phi { opcode: ir::instructions::OpCode::Phi, dst: e , from: vec![(b2, a_inner), (b1, a)] } + &b2, + ir::instructions::InstructionData::Phi { + opcode: ir::instructions::OpCode::Phi, + dst: e, + from: vec![(b2, a_inner), (b1, a)], + }, ); // exit function.switch_to_block(b3); @@ -256,4 +259,4 @@ pub fn create_licm_graph_example_from_cmu() -> Function { function.build_ret_inst(None); function -} \ No newline at end of file +} diff --git a/compilers/rustyc/optimizer/tests/build_ir_graph.rs b/compilers/rustyc/optimizer/tests/build_ir_graph.rs index 9c11d950..21ba28ca 100644 --- a/compilers/rustyc/optimizer/tests/build_ir_graph.rs +++ b/compilers/rustyc/optimizer/tests/build_ir_graph.rs @@ -262,8 +262,12 @@ pub fn create_licm_graph_simple_example_from_cmu() -> Function { let a_inner = function.build_add_inst(b, c); let e = function.add_register(IrValueType::I16); function.insert_inst_to_block_front( - &b2, - ir::instructions::InstructionData::Phi { opcode: ir::instructions::OpCode::Phi, dst: e , from: vec![(b2, a_inner), (b1, a)] } + &b2, + ir::instructions::InstructionData::Phi { + opcode: ir::instructions::OpCode::Phi, + dst: e, + from: vec![(b2, a_inner), (b1, a)], + }, ); // exit function.switch_to_block(b3); diff --git a/compilers/rustyc/optimizer/tests/ir_optimizer_test_runner.rs b/compilers/rustyc/optimizer/tests/ir_optimizer_test_runner.rs index 56251b89..ce37dcad 100644 --- a/compilers/rustyc/optimizer/tests/ir_optimizer_test_runner.rs +++ b/compilers/rustyc/optimizer/tests/ir_optimizer_test_runner.rs @@ -132,21 +132,19 @@ generate_pass_cases!( let after = fun.print_to_string(); (before, table, after) }), - ( - test_licm_pass_cmu_example_2, "./licm/cmu_example_2", || { - let mut fun = create_licm_graph_simple_example_from_cmu(); - let before = fun.print_to_string(); - let mut dom = DomAnaylsier::new(); - let dom_table = dom.anaylsis(&fun); - let mut use_def = UseDefAnaylsier::new(); - let use_def_table = use_def.anaylsis(&fun); - let mut pass = LICMPass::new(&use_def_table, &dom_table); - pass.process(&mut fun); - let table = pass.debugger(&fun); - let after = fun.print_to_string(); - (before, table, after) - } - ) + (test_licm_pass_cmu_example_2, "./licm/cmu_example_2", || { + let mut fun = create_licm_graph_simple_example_from_cmu(); + let before = fun.print_to_string(); + let mut dom = DomAnaylsier::new(); + let dom_table = dom.anaylsis(&fun); + let mut use_def = UseDefAnaylsier::new(); + let use_def_table = use_def.anaylsis(&fun); + let mut pass = LICMPass::new(&use_def_table, &dom_table); + pass.process(&mut fun); + let table = pass.debugger(&fun); + let after = fun.print_to_string(); + (before, table, after) + }) ); #[test]