Skip to content

Compiler: reduce number of deadcode pass #1998

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

Closed
wants to merge 2 commits into from
Closed
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
45 changes: 25 additions & 20 deletions compiler/lib/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,30 @@ let tailcall p =
if debug () then Format.eprintf "Tail-call optimization...@.";
Tailcall.f p

let deadcode' p =
let deadcode p =
if debug () then Format.eprintf "Dead-code...@.";
Deadcode.f p

let deadcode p =
let p, _ = deadcode' p in
let deadcode_and_inline (profile : Profile.t) p =
let p, live_vars = deadcode p in
let p =
if Config.Flag.inline () && Config.Flag.deadcode ()
then (
if debug () then Format.eprintf "Inlining...@.";
Inline.f p live_vars)
else p
in
let p =
match profile with
| O1 -> p
| O2 | O3 ->
let p, _ = deadcode p in
p
in
let p = Deadcode.merge_blocks p in
let p = Code.compact p in
p

let inline p =
if Config.Flag.inline () && Config.Flag.deadcode ()
then (
let p, live_vars = deadcode' p in
if debug () then Format.eprintf "Inlining...@.";
Inline.f p live_vars)
else p

let specialize_1 (p, info) =
if debug () then Format.eprintf "Specialize...@.";
Specialize.f ~function_arity:(fun f -> Specialize.function_arity info f) p
Expand Down Expand Up @@ -96,13 +102,13 @@ let effects ~deadcode_sentinal p =
match Config.effects () with
| `Cps | `Double_translation ->
if debug () then Format.eprintf "Effects...@.";
let p, live_vars = Deadcode.f p in
let p, live_vars = deadcode p in
let info = Global_flow.f ~fast:false p in
let p, live_vars =
if Config.Flag.globaldeadcode ()
then
let p = Global_deadcode.f p ~deadcode_sentinal info in
Deadcode.f p
deadcode p
else p, live_vars
in
p
Expand Down Expand Up @@ -153,27 +159,26 @@ let rec loop max name round i (p : 'a) : 'a =
p')
else loop max name round (i + 1) p'

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

(* o1 *)

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

(* o2 *)

let o2 = loop 10 "round" round 1 +> print
let o2 = loop 10 "round" (round O2) 1 +> print

(* o3 *)

let o3 = loop 30 "round" round 1 +> print
let o3 = loop 30 "round" (round O3) 1 +> print

let generate
~exported_runtime
Expand Down Expand Up @@ -640,7 +645,7 @@ let optimize ~profile p =
| `JavaScript, `Disabled -> Generate_closure.f
| `JavaScript, (`Cps | `Double_translation) | `Wasm, (`Jspi | `Cps) -> Fun.id
| `JavaScript, `Jspi | `Wasm, (`Disabled | `Double_translation) -> assert false)
+> map_fst deadcode'
+> map_fst deadcode
in
if times () then Format.eprintf "Start Optimizing...@.";
let t = Timer.make () in
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