Skip to content

Commit 68370fb

Browse files
committed
Compiler: reorder optimisation passes
1 parent 18e0872 commit 68370fb

File tree

3 files changed

+309
-299
lines changed

3 files changed

+309
-299
lines changed

compiler/lib/driver.ml

+5-12
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let specialize (p, info) =
7878
let p = specialize_js (p, info) in
7979
p, info
8080

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

8383
let flow p =
8484
if debug () then Format.eprintf "Data flow...@.";
@@ -142,7 +142,7 @@ let stats = Debug.find "stats"
142142
let rec loop max name round i (p : 'a) : 'a =
143143
let debug = times () || stats () in
144144
if debug then Format.eprintf "%s#%d...@." name i;
145-
let p' = round ~first:(i = 1) p in
145+
let p' = round p in
146146
if i >= max
147147
then (
148148
if debug then Format.eprintf "%s#%d: couldn't reach fix point.@." name i;
@@ -153,19 +153,12 @@ let rec loop max name round i (p : 'a) : 'a =
153153
p')
154154
else loop max name round (i + 1) p'
155155

156-
let round ~first : 'a -> 'a =
157-
print
158-
+> tailcall
159-
+> (if first then Fun.id else phi)
160-
+> flow
161-
+> specialize
162-
+> eval
163-
+> inline
164-
+> deadcode
156+
let round : 'a -> 'a =
157+
print +> tailcall +> (flow +> specialize +> eval +> fst) +> inline +> phi +> deadcode
165158

166159
(* o1 *)
167160

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

170163
(* o2 *)
171164

compiler/tests-compiler/static_eval.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ let%expect_test "static eval of string get" =
142142
key = param[1],
143143
data = param[2],
144144
next = param[3],
145-
r = [0, key, data, next],
146-
prec = r,
145+
prec$1 = [0, key, data, next],
146+
prec = prec$1,
147147
param$0 = next;
148148
for(;;){
149-
if(! param$0) return r;
149+
if(! param$0) return prec$1;
150150
var
151151
key$0 = param$0[1],
152152
data$0 = param$0[2],

0 commit comments

Comments
 (0)