Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize expressions in basic blocks #22

Merged
merged 5 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "files"


[dependencies]
egglog = { git = "https://github.com/egraphs-good/egglog", rev = "a4768b1" }
egglog = { git = "https://github.com/egraphs-good/egglog", rev = "c83fc75" }
log = "0.4.19"
thiserror = "1"
lalrpop-util = { version = "0.19.8", features = ["lexer"] }
Expand Down
601 changes: 301 additions & 300 deletions src/conversions.rs

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@ impl Optimizer {
let mut keys = egg_fns.keys().collect::<Vec<&String>>();
keys.sort();

let mut termdag = Default::default();
let mut result = vec![];
for name in keys {
let expr = egg_fns.get(name).unwrap();
let mut rep = egraph
.extract_expr(expr.clone(), 0)
let (sort, value) = egraph
.eval_expr(expr, None, true)
.map_err(EggCCError::EggLog)?;
let extracted = rep.termdag.term_to_expr(&rep.expr);
let structured_func = self.expr_to_structured_func(extracted);
let (_cost, term) = egraph.extract(value, &mut termdag, &sort);
let structured_func = self.term_to_structured_func(&termdag, &term);

result.push(structured_func);
}
Expand Down Expand Up @@ -285,7 +286,7 @@ impl Optimizer {
(lt Type Expr Expr)
(ptradd Type Expr Expr)
(load Type Expr)

)

(datatype RetVal
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshots/files__add_naiive.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ expression: "format!(\"{}\", res)"
v0: int = const 1;
v1: int = const 2;
v2: int = const 3;
v0_: int = const 3;
print v0_;
print v2;
ret;
.sblock___0:
.exit___:
Expand Down
9 changes: 2 additions & 7 deletions tests/snapshots/files__add_naiive_no_opt.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ expression: "format!(\"{}\", res)"
.entry___:
v0: int = const 1;
v1: int = const 2;
v0_: int = const 1;
v1_: int = const 2;
v2: int = add v0_ v1_;
v3_: int = const 1;
v4_: int = const 2;
v2_: int = add v3_ v4_;
print v2_;
v2: int = add v0 v1;
print v2;
ret;
.sblock___0:
.exit___:
Expand Down
4 changes: 1 addition & 3 deletions tests/snapshots/files__block-diamond_naiive.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ expression: "format!(\"{}\", res)"
one: int = const 1;
two: int = const 2;
x: int = const 0;
v0_: int = const 1;
v1_: int = const 2;
a_cond: bool = lt v0_ v1_;
a_cond: bool = lt one two;
br a_cond .sblock___4 .sblock___5;
.sblock___4:
jmp .sblock___2;
Expand Down
4 changes: 1 addition & 3 deletions tests/snapshots/files__block-diamond_naiive_no_opt.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ expression: "format!(\"{}\", res)"
one: int = const 1;
two: int = const 2;
x: int = const 0;
v0_: int = const 1;
v1_: int = const 2;
a_cond: bool = lt v0_ v1_;
a_cond: bool = lt one two;
br a_cond .sblock___4 .sblock___5;
.sblock___4:
jmp .sblock___2;
Expand Down
4 changes: 1 addition & 3 deletions tests/snapshots/files__diamond_naiive.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ expression: "format!(\"{}\", res)"
@main {
.entry___:
x: int = const 4;
v0_: int = const 4;
v1_: int = const 4;
cond: bool = lt v0_ v1_;
cond: bool = lt x x;
br cond .sblock___3 .sblock___4;
.sblock___3:
jmp .sblock___1;
Expand Down
4 changes: 1 addition & 3 deletions tests/snapshots/files__diamond_naiive_no_opt.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ expression: "format!(\"{}\", res)"
@main {
.entry___:
x: int = const 4;
v0_: int = const 4;
v1_: int = const 4;
cond: bool = lt v0_ v1_;
cond: bool = lt x x;
br cond .sblock___3 .sblock___4;
.sblock___3:
jmp .sblock___1;
Expand Down
8 changes: 2 additions & 6 deletions tests/snapshots/files__two_fns_naiive_no_opt.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ expression: "format!(\"{}\", res)"
.entry___:
v0: int = const 1;
v1: int = const 2;
v0_: int = const 1;
v1_: int = const 2;
v2: int = add v0_ v1_;
v2: int = add v0 v1;
ret;
.sblock___0:
.exit___:
Expand All @@ -17,9 +15,7 @@ expression: "format!(\"{}\", res)"
.entry___:
v0: int = const 1;
v1: int = const 2;
v2_: int = const 1;
v3_: int = const 2;
v2: int = sub v2_ v3_;
v2: int = sub v0 v1;
ret;
.sblock___0:
.exit___:
Expand Down