Skip to content

Commit

Permalink
feat: add licm pass test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Solo-steven committed Sep 24, 2024
1 parent 457ed01 commit 9758834
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
11 changes: 7 additions & 4 deletions compilers/rustyc/optimizer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -256,4 +259,4 @@ pub fn create_licm_graph_example_from_cmu() -> Function {
function.build_ret_inst(None);

function
}
}
8 changes: 6 additions & 2 deletions compilers/rustyc/optimizer/tests/build_ir_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 13 additions & 15 deletions compilers/rustyc/optimizer/tests/ir_optimizer_test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9758834

Please sign in to comment.