Skip to content

Commit

Permalink
Add some LVM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjoseph1995 committed Oct 26, 2024
1 parent 62eaabe commit aee8e72
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*Cargo.lock
target/
.vscode/
44 changes: 34 additions & 10 deletions optimizations/src/local_value_numbering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,15 @@ mod tests {
assert_ne!(tuple1, tuple2);
}

fn parse_program(text: &str) -> Program {
let program = common::parse_bril_text(text);
assert!(program.is_ok());
program.unwrap()
}

#[test]
fn test_local_lvn_1() {
const BRIL_PROGRAM_TEXT: &'static str = indoc::indoc! {r#"
fn test_local_lvn_no_redundant_computation_1() {
let program = parse_program(indoc::indoc! {r#"
@main() {
a: int = const 1;
b: int = const 2;
Expand All @@ -339,30 +345,48 @@ mod tests {
d: int = add a b;
print d;
}
"#};
let program = common::parse_bril_text(&BRIL_PROGRAM_TEXT);
assert!(program.is_ok());
let program = program.unwrap();
"#});
let mut manager = LocalValueNumberingPass::new();
let program = Pass::apply(&mut manager, program);
println!("\n\n{}", program);
let expected_program = program.clone();
assert_eq!(program, expected_program);
}

#[test]
fn test_local_lvn_2() {
fn test_local_lvn_no_redundant_computation_2() {
let program = parse_program(indoc::indoc! {r#"
@main() {
a: int = const 1;
b: int = id a;
c: int = add a b;
print c;
}
"#});
let mut manager = LocalValueNumberingPass::new();
let program = Pass::apply(&mut manager, program);
let expected_program = program.clone();
assert_eq!(program, expected_program);
}

#[test]
fn test_local_lvn_3() {
const BRIL_PROGRAM_TEXT: &'static str = indoc::indoc! {r#"
@main() {
a: int = const 1;
b: int = id a;
c: int = add a b;
print c;
x: int = id a;
y: int = id a;
z: int = id a;
d: int = add a b;
print d;
}
"#};
let program = common::parse_bril_text(&BRIL_PROGRAM_TEXT);
assert!(program.is_ok());
let program = program.unwrap();
let mut manager = LocalValueNumberingPass::new();
let program = Pass::apply(&mut manager, program);
println!("\n\n{}", program);
println!("{}", program);
}
}

0 comments on commit aee8e72

Please sign in to comment.