Skip to content

Commit

Permalink
feat(lvn): Reorder commutative operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanuppal committed Feb 7, 2025
1 parent 0c07b8b commit 4caa5fa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
21 changes: 21 additions & 0 deletions lesson3/brench_no_args.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extract = 'total_dyn_inst: (\d+)'
timeout = 200

[runs.baseline]
pipeline = ["bril2json", "brili -p"]

[runs.tdce]
pipeline = ["bril2json", "../target/debug/tdce", "bril2json", "brili -p"]

[runs.lvn]
pipeline = ["bril2json", "../target/debug/lvn", "bril2json", "brili -p"]

[runs.lvn_then_tdce]
pipeline = [
"bril2json",
"../target/debug/lvn",
"bril2json",
"../target/debug/tdce",
"bril2json",
"brili -p",
]
19 changes: 17 additions & 2 deletions lesson3/lvn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Opts {
input: Option<PathBuf>,
}

#[derive(PartialEq, Eq, Hash, Clone)]
#[derive(PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
enum OpArg {
Value(usize),
Unknown(String),
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn lvn(block: &mut BasicBlock) {
} => {
let is_overwritten =
last_assignment.get(dest).copied().unwrap() > i;
let new_args = args
let mut new_args = args
.iter()
.map(|arg| {
table
Expand All @@ -253,6 +253,21 @@ pub fn lvn(block: &mut BasicBlock) {
.unwrap_or(OpArg::Unknown(arg.clone()))
})
.collect::<Vec<_>>();
if matches!(
op,
ValueOps::Add
| ValueOps::Fadd
| ValueOps::Mul
| ValueOps::Fmul
| ValueOps::Eq
| ValueOps::Feq
| ValueOps::And
| ValueOps::Or
| ValueOps::Ceq
| ValueOps::Phi
) {
new_args.sort();
}
match table.add_value_and_get_existing_variable(
Value::Op(*op, new_args.clone()),
dest,
Expand Down

0 comments on commit 4caa5fa

Please sign in to comment.