Skip to content

Commit 70e463e

Browse files
committed
use profile to comtrol exact calls
1 parent dfae974 commit 70e463e

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

compiler/lib/driver.ml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ let debug = Debug.find "main"
2323

2424
let times = Debug.find "times"
2525

26+
type profile =
27+
| O1
28+
| O2
29+
| O3
30+
2631
let should_export = function
2732
| `Iife -> false
2833
| `Named _ | `Anonymous -> true
@@ -91,10 +96,15 @@ let effects p =
9196
p |> Deadcode.f +> Effects.f +> map_fst Lambda_lifting.f)
9297
else p, (Code.Var.Set.empty : Effects.cps_calls)
9398

94-
let exact_calls p =
99+
let exact_calls profile p =
95100
if not (Config.Flag.effects ())
96101
then
97-
let info = Global_flow.f p in
102+
let fast =
103+
match profile with
104+
| O3 -> false
105+
| O1 | O2 -> true
106+
in
107+
let info = Global_flow.f ~fast p in
98108
Specialize.f ~function_arity:(fun f -> Global_flow.function_arity info f) p
99109
else p
100110

@@ -558,8 +568,6 @@ let configure formatter =
558568
Code.Var.set_pretty (pretty && not (Config.Flag.shortvar ()));
559569
Code.Var.set_stable (Config.Flag.stable_var ())
560570

561-
type profile = Code.program -> Code.program
562-
563571
let full
564572
~standalone
565573
~wrap_with_fun
@@ -573,8 +581,11 @@ let full
573581
let exported_runtime = not standalone in
574582
let opt =
575583
specialize_js_once
576-
+> profile
577-
+> exact_calls
584+
+> (match profile with
585+
| O1 -> o1
586+
| O2 -> o2
587+
| O3 -> o3)
588+
+> exact_calls profile
578589
+> effects
579590
+> map_fst (Generate_closure.f +> deadcode')
580591
in
@@ -618,7 +629,7 @@ let full_no_source_map
618629
let f
619630
?(standalone = true)
620631
?(wrap_with_fun = `Iife)
621-
?(profile = o1)
632+
?(profile = O1)
622633
?(linkall = false)
623634
?source_map
624635
?custom_header
@@ -639,7 +650,7 @@ let f
639650
let f'
640651
?(standalone = true)
641652
?(wrap_with_fun = `Iife)
642-
?(profile = o1)
653+
?(profile = O1)
643654
?(linkall = false)
644655
?custom_header
645656
formatter
@@ -660,13 +671,13 @@ let from_string ~prims ~debug s formatter =
660671
full_no_source_map
661672
~standalone:false
662673
~wrap_with_fun:`Anonymous
663-
~profile:o1
674+
~profile:O1
664675
~linkall:false
665676
~custom_header:None
666677
formatter
667678
d
668679
p
669680

670-
let profiles = [ 1, o1; 2, o2; 3, o3 ]
681+
let profiles = [ 1, O1; 2, O2; 3, O3 ]
671682

672683
let profile i = try Some (List.assoc i profiles) with Not_found -> None

compiler/lib/effects.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ let remove_empty_blocks ~live_vars (p : Code.program) : Code.program =
882882
let f (p, live_vars) =
883883
let t = Timer.make () in
884884
let p = remove_empty_blocks ~live_vars p in
885-
let flow_info = Global_flow.f p in
885+
let flow_info = Global_flow.f ~fast:false p in
886886
let cps_needed = Partial_cps_analysis.f p flow_info in
887887
let p, cps_needed = rewrite_toplevel ~cps_needed p in
888888
let p = split_blocks ~cps_needed p in

compiler/lib/global_flow.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ type info =
545545
; info_may_escape : bool array
546546
}
547547

548-
let f p =
548+
let f ~fast p =
549549
let t = Timer.make () in
550550
let t1 = Timer.make () in
551551
let rets = return_values p in
@@ -568,7 +568,7 @@ let f p =
568568
; possibly_mutable
569569
; known_cases = Hashtbl.create 16
570570
; applied_functions = Hashtbl.create 16
571-
; fast = not (Config.Flag.effects ())
571+
; fast
572572
}
573573
in
574574
program_deps st p;

compiler/lib/global_flow.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type info =
3737
; info_may_escape : bool array
3838
}
3939

40-
val f : Code.program -> info
40+
val f : fast:bool -> Code.program -> info
4141

4242
val exact_call : info -> Var.t -> int -> bool
4343

0 commit comments

Comments
 (0)