Skip to content

Compiler: reorder optimization passes #2001

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

Merged
merged 2 commits into from
May 17, 2025
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
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
* Compiler: improve deadcode optimization (#1963, #1962, #1967)
* Compiler: improve coloring optimization (#1971, #1984, #1986, #1989)
* Compiler: faster constant sharing (#1988)
* Compiler: faster wat output (#1992)
* Compiler: faster js code generation (#1985)
* Compiler: more efficient code generation from bytecode (#1972)
* Runtime: use Dataview to convert between floats and bit representation
* Compiler: speed-up compilation by improving the scheduling of optimization passes (#1962)
* Compiler: speed-up compilation by improving the scheduling of optimization passes (#1962, #2001)
* Compiler: deadcode elimination of cyclic values (#1978)
* Compiler: directly write Wasm binary modules (#2000, #2003)

Expand Down
17 changes: 5 additions & 12 deletions compiler/lib/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let specialize (p, info) =
let p = specialize_js (p, info) in
p, info

let eval (p, info) = if Config.Flag.staticeval () then Eval.f info p else p
let eval (p, info) = if Config.Flag.staticeval () then Eval.f info p, info else p, info

let flow p =
if debug () then Format.eprintf "Data flow...@.";
Expand Down Expand Up @@ -142,7 +142,7 @@ let stats = Debug.find "stats"
let rec loop max name round i (p : 'a) : 'a =
let debug = times () || stats () in
if debug then Format.eprintf "%s#%d...@." name i;
let p' = round ~first:(i = 1) p in
let p' = round p in
if i >= max
then (
if debug then Format.eprintf "%s#%d: couldn't reach fix point.@." name i;
Expand All @@ -153,19 +153,12 @@ let rec loop max name round i (p : 'a) : 'a =
p')
else loop max name round (i + 1) p'

let round ~first : 'a -> 'a =
print
+> tailcall
+> (if first then Fun.id else phi)
+> flow
+> specialize
+> eval
+> inline
+> deadcode
let round : 'a -> 'a =
print +> tailcall +> (flow +> specialize +> eval +> fst) +> inline +> phi +> deadcode

(* o1 *)

let o1 = loop 2 "round" round 1 +> phi +> flow +> specialize +> eval +> print
let o1 = loop 2 "round" round 1 +> (flow +> specialize +> eval +> fst) +> print

(* o2 *)

Expand Down
6 changes: 3 additions & 3 deletions compiler/tests-compiler/static_eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ let%expect_test "static eval of string get" =
key = param[1],
data = param[2],
next = param[3],
r = [0, key, data, next],
prec = r,
prec$1 = [0, key, data, next],
prec = prec$1,
param$0 = next;
for(;;){
if(! param$0) return r;
if(! param$0) return prec$1;
var
key$0 = param$0[1],
data$0 = param$0[2],
Expand Down
Loading
Loading