Skip to content

Commit 26b0106

Browse files
vouillonhhugo
authored andcommitted
Omit phi simplification pass in the first round
It is expensive and does not bring much
1 parent b13ff9b commit 26b0106

12 files changed

+2276
-2143
lines changed

compiler/lib/driver.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let stats = Debug.find "stats"
147147
let rec loop max name round i (p : 'a) : 'a =
148148
let debug = times () || stats () in
149149
if debug then Format.eprintf "%s#%d...@." name i;
150-
let p' = round p in
150+
let p' = round ~first:(i = 1) p in
151151
if i >= max
152152
then (
153153
if debug then Format.eprintf "%s#%d: couldn't reach fix point.@." name i;
@@ -158,8 +158,15 @@ let rec loop max name round i (p : 'a) : 'a =
158158
p')
159159
else loop max name round (i + 1) p'
160160

161-
let round : 'a -> 'a =
162-
print +> tailcall +> phi +> flow +> specialize +> eval +> inline +> deadcode
161+
let round ~first : 'a -> 'a =
162+
print
163+
+> tailcall
164+
+> (if first then Fun.id else phi)
165+
+> flow
166+
+> specialize
167+
+> eval
168+
+> inline
169+
+> deadcode
163170

164171
(* o1 *)
165172

compiler/tests-compiler/double-translation/effects_continuations.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
103103
function exceptions$0(s){
104104
try{var _C_ = caml_int_of_string(s), n = _C_;}
105105
catch(exn$0){
106-
var exn = caml_wrap_exception(exn$0), tag = exn[1];
107-
if(tag !== Stdlib[7]) throw caml_maybe_attach_backtrace(exn, 0);
106+
var exn = caml_wrap_exception(exn$0);
107+
if(exn[1] !== Stdlib[7]) throw caml_maybe_attach_backtrace(exn, 0);
108108
var n = 0;
109109
}
110110
try{
@@ -133,8 +133,8 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
133133
function exceptions$1(s, cont){
134134
try{var _y_ = caml_int_of_string(s), n = _y_;}
135135
catch(exn){
136-
var exn$2 = caml_wrap_exception(exn), tag = exn$2[1];
137-
if(tag !== Stdlib[7]){
136+
var exn$2 = caml_wrap_exception(exn);
137+
if(exn$2[1] !== Stdlib[7]){
138138
var
139139
raise$1 = caml_pop_trap(),
140140
exn$0 = caml_maybe_attach_backtrace(exn$2, 0);

compiler/tests-compiler/double-translation/effects_exceptions.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
5858
function exceptions$0(s){
5959
try{var _p_ = caml_int_of_string(s), n = _p_;}
6060
catch(exn$0){
61-
var exn = caml_wrap_exception(exn$0), tag = exn[1];
62-
if(tag !== Stdlib[7]) throw caml_maybe_attach_backtrace(exn, 0);
61+
var exn = caml_wrap_exception(exn$0);
62+
if(exn[1] !== Stdlib[7]) throw caml_maybe_attach_backtrace(exn, 0);
6363
var n = 0;
6464
}
6565
try{
@@ -88,8 +88,8 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
8888
function exceptions$1(s, cont){
8989
try{var _l_ = caml_int_of_string(s), n = _l_;}
9090
catch(exn){
91-
var exn$2 = caml_wrap_exception(exn), tag = exn$2[1];
92-
if(tag !== Stdlib[7]){
91+
var exn$2 = caml_wrap_exception(exn);
92+
if(exn$2[1] !== Stdlib[7]){
9393
var
9494
raise$1 = caml_pop_trap(),
9595
exn$0 = caml_maybe_attach_backtrace(exn$2, 0);
@@ -136,8 +136,8 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
136136
catch(exn$0){
137137
var l$0 = l;
138138
for(;;){
139-
var match = caml_call1(g, l$0), variant = match[1];
140-
if(72330306 > variant){
139+
var match = caml_call1(g, l$0);
140+
if(72330306 > match[1]){
141141
var exn = match[2];
142142
throw caml_maybe_attach_backtrace(exn, 1);
143143
}
@@ -155,8 +155,7 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
155155
(g,
156156
l,
157157
function(match){
158-
var variant = match[1];
159-
if(72330306 <= variant){
158+
if(72330306 <= match[1]){
160159
var l = match[2];
161160
return caml_exact_trampoline_call1(_h_, l);
162161
}

compiler/tests-compiler/effects_continuations.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
104104
function exceptions(s, cont){
105105
try{var _y_ = runtime.caml_int_of_string(s), n = _y_;}
106106
catch(exn$0){
107-
var exn = caml_wrap_exception(exn$0), tag = exn[1];
108-
if(tag !== Stdlib[7]){
107+
var exn = caml_wrap_exception(exn$0);
108+
if(exn[1] !== Stdlib[7]){
109109
var raise$1 = caml_pop_trap(), exn$2 = caml_maybe_attach_backtrace(exn, 0);
110110
return raise$1(exn$2);
111111
}

compiler/tests-compiler/effects_exceptions.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
5858
function exceptions(s, cont){
5959
try{var _j_ = runtime.caml_int_of_string(s), n = _j_;}
6060
catch(exn$0){
61-
var exn = caml_wrap_exception(exn$0), tag = exn[1];
62-
if(tag !== Stdlib[7]){
61+
var exn = caml_wrap_exception(exn$0);
62+
if(exn[1] !== Stdlib[7]){
6363
var raise$1 = caml_pop_trap(), exn$2 = caml_maybe_attach_backtrace(exn, 0);
6464
return raise$1(exn$2);
6565
}
@@ -107,8 +107,7 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
107107
(g,
108108
l,
109109
function(match){
110-
var variant = match[1];
111-
if(72330306 <= variant){
110+
if(72330306 <= match[1]){
112111
var l = match[2];
113112
return caml_exact_trampoline_call1(_g_, l);
114113
}

compiler/tests-compiler/es6.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ let rec odd n' = function
6161
for(;;){
6262
if(0 === c) return [0, d, 0];
6363
if(1 === c) return [0, d, 1];
64-
[d, c] = [(c - 1 | 0) - 1 | 0, (d - 1 | 0) - 1 | 0];
64+
[c, d] = [(d - 1 | 0) - 1 | 0, (c - 1 | 0) - 1 | 0];
6565
}}],
6666
"Test");
6767
return;})

compiler/tests-compiler/gh1007.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,7 @@ let () = M.run ()
633633
let odd$0 = odd, even$0 = even;
634634
var param$0 = even(i);
635635
for(;;){
636-
var variant = param$0[1];
637-
if(759635106 <= variant) break;
636+
if(759635106 <= param$0[1]) break;
638637
var f = param$0[2];
639638
param$0 = f(0);
640639
}

compiler/tests-compiler/gh1868.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ let wrap f =
4343
catch(exn$1){
4444
var exn = caml_wrap_exception(exn$1);
4545
for(;;){
46-
var tag = exn[1];
47-
if(tag !== Nested) throw caml_maybe_attach_backtrace(exn, 1);
46+
if(exn[1] !== Nested) throw caml_maybe_attach_backtrace(exn, 1);
4847
var exn$0 = exn[2];
4948
exn = exn$0;
5049
}
@@ -53,8 +52,7 @@ let wrap f =
5352
//end
5453
function wrap$1(f, cont){
5554
function _b_(exn$1){
56-
var tag = exn$1[1];
57-
if(tag === Nested){
55+
if(exn$1[1] === Nested){
5856
var exn$0 = exn$1[2];
5957
return caml_exact_trampoline_call1(_b_, exn$0);
6058
}

compiler/tests-compiler/inlining.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ let%expect_test "inline small function exposing more tc" =
5050
[%expect
5151
{|
5252
function f(g, x){
53-
var variant$0 = x[1];
54-
if(106380200 <= variant$0) return x;
55-
var v$0 = x[2], x$0 = caml_call1(g, v$0), variant = x$0[1];
56-
if(106380200 <= variant) return x$0;
53+
if(106380200 <= x[1]) return x;
54+
var v$0 = x[2], x$0 = caml_call1(g, v$0);
55+
if(106380200 <= x$0[1]) return x$0;
5756
var v = x$0[2];
5857
return v;
5958
}

compiler/tests-compiler/loops.ml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ let rec fun_with_loop acc = function
8585
return caml_call1
8686
(list_rev, caml_call1(list_rev, caml_call1(list_rev, acc)));
8787
var x = param[1];
88-
if(1 === x && ! param[2]){
89-
var a$0 = [0, acc], i$0 = 0;
90-
for(;;){
91-
a$0[1] = [0, 1, a$0[1]];
92-
var _b_ = i$0 + 1 | 0;
93-
if(10 === i$0) return a$0[1];
94-
i$0 = _b_;
95-
}
96-
}
88+
if(1 === x && ! param[2]) break;
9789
var xs = param[2], a = [0, acc], i = 0;
9890
for(;;){
9991
a[1] = [0, 1, a[1]];
@@ -105,6 +97,13 @@ let rec fun_with_loop acc = function
10597
acc = acc$0;
10698
param = xs;
10799
}
100+
var a$0 = [0, acc], i$0 = 0;
101+
for(;;){
102+
a$0[1] = [0, 1, a$0[1]];
103+
var _b_ = i$0 + 1 | 0;
104+
if(10 === i$0) return a$0[1];
105+
i$0 = _b_;
106+
}
108107
}
109108
//end
110109
|}]
@@ -131,12 +130,14 @@ let for_for_while () =
131130
var k = 1;
132131
for(;;){
133132
var j = 1;
134-
for(;;){
135-
for(;;){if(10 <= runtime.caml_mul(k, j)) break; id[1]++;}
136-
var _b_ = j + 1 | 0;
137-
if(10 === j) break;
138-
j = _b_;
139-
}
133+
for(;;)
134+
if(10 <= runtime.caml_mul(k, j)){
135+
var _b_ = j + 1 | 0;
136+
if(10 === j) break;
137+
j = _b_;
138+
}
139+
else
140+
id[1]++;
140141
var _a_ = k + 1 | 0;
141142
if(10 === k) return 0;
142143
k = _a_;
@@ -168,17 +169,17 @@ let for_for_while () =
168169
var k = 1;
169170
for(;;){
170171
var j = 1;
171-
for(;;){
172-
for(;;){
173-
if(10 <= caml_div(k, j)) break;
172+
for(;;)
173+
if(10 <= caml_div(k, j)){
174+
var _b_ = j + 1 | 0;
175+
if(10 === j) break;
176+
j = _b_;
177+
}
178+
else{
174179
try{caml_div(k, j);}
175180
catch(exn){throw caml_maybe_attach_backtrace(Stdlib[8], 1);}
176181
id[1]++;
177182
}
178-
var _b_ = j + 1 | 0;
179-
if(10 === j) break;
180-
j = _b_;
181-
}
182183
var _a_ = k + 1 | 0;
183184
if(10 === k) return 0;
184185
k = _a_;

compiler/tests-compiler/match_with_exn.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ let fun2 () =
7777
{
7878
try{var i$1 = caml_call1(Stdlib_Random[5], 2);}
7979
catch(exn$0){
80-
var exn = caml_wrap_exception(exn$0), tag = exn[1];
81-
if(tag !== A) throw caml_maybe_attach_backtrace(exn, 0);
80+
var exn = caml_wrap_exception(exn$0);
81+
if(exn[1] !== A) throw caml_maybe_attach_backtrace(exn, 0);
8282
var i = exn[2];
8383
if(2 !== i) return i + 2 | 0;
8484
var i$0 = i;

0 commit comments

Comments
 (0)