Skip to content

Commit 1f25caf

Browse files
authored
feat: Implement optimization settings api (#243)
* feat: Implement optimization flags * feat: Add Pass Settings * `clear_pass_arguments` * `has_pass_to_skip` * `Add_pass_to_skip` * `clear_passes_to_skip` * chore: Test build failure
1 parent dd6bfa7 commit 1f25caf

File tree

5 files changed

+385
-0
lines changed

5 files changed

+385
-0
lines changed

src/settings.c

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ caml_binaryen_set_debug_info(value _on) {
5252
CAMLreturn(Val_unit);
5353
}
5454

55+
CAMLprim value
56+
caml_binaryen_get_traps_never_happen(value unit) {
57+
CAMLparam1(unit);
58+
bool res = BinaryenGetTrapsNeverHappen();
59+
CAMLreturn(Val_bool(res));
60+
}
61+
62+
CAMLprim value
63+
caml_binaryen_set_traps_never_happen(value _on) {
64+
CAMLparam1(_on);
65+
bool on = Bool_val(_on);
66+
BinaryenSetTrapsNeverHappen(on);
67+
CAMLreturn(Val_unit);
68+
}
69+
70+
CAMLprim value
71+
caml_binaryen_get_closed_world(value unit) {
72+
CAMLparam1(unit);
73+
bool res = BinaryenGetClosedWorld();
74+
CAMLreturn(Val_bool(res));
75+
}
76+
77+
CAMLprim value
78+
caml_binaryen_set_closed_world(value _on) {
79+
CAMLparam1(_on);
80+
bool on = Bool_val(_on);
81+
BinaryenSetClosedWorld(on);
82+
CAMLreturn(Val_unit);
83+
}
84+
5585
CAMLprim value
5686
caml_binaryen_get_low_memory_unused(value unit) {
5787
CAMLparam1(unit);
@@ -67,6 +97,66 @@ caml_binaryen_set_low_memory_unused(value _on) {
6797
CAMLreturn(Val_unit);
6898
}
6999

100+
CAMLprim value
101+
caml_binaryen_get_zero_filled_memory(value unit) {
102+
CAMLparam1(unit);
103+
bool res = BinaryenGetZeroFilledMemory();
104+
CAMLreturn(Val_bool(res));
105+
}
106+
107+
CAMLprim value
108+
caml_binaryen_set_zero_filled_memory(value _on) {
109+
CAMLparam1(_on);
110+
bool on = Bool_val(_on);
111+
BinaryenSetZeroFilledMemory(on);
112+
CAMLreturn(Val_unit);
113+
}
114+
115+
CAMLprim value
116+
caml_binaryen_get_fast_math(value unit) {
117+
CAMLparam1(unit);
118+
bool res = BinaryenGetFastMath();
119+
CAMLreturn(Val_bool(res));
120+
}
121+
122+
CAMLprim value
123+
caml_binaryen_set_fast_math(value _on) {
124+
CAMLparam1(_on);
125+
bool on = Bool_val(_on);
126+
BinaryenSetFastMath(on);
127+
CAMLreturn(Val_unit);
128+
}
129+
130+
CAMLprim value
131+
caml_binaryen_get_generate_stack_ir(value unit) {
132+
CAMLparam1(unit);
133+
bool res = BinaryenGetGenerateStackIR();
134+
CAMLreturn(Val_bool(res));
135+
}
136+
137+
CAMLprim value
138+
caml_binaryen_set_generate_stack_ir(value _on) {
139+
CAMLparam1(_on);
140+
bool on = Bool_val(_on);
141+
BinaryenSetGenerateStackIR(on);
142+
CAMLreturn(Val_unit);
143+
}
144+
145+
CAMLprim value
146+
caml_binaryen_get_optimize_stack_ir(value unit) {
147+
CAMLparam1(unit);
148+
bool res = BinaryenGetOptimizeStackIR();
149+
CAMLreturn(Val_bool(res));
150+
}
151+
152+
CAMLprim value
153+
caml_binaryen_set_optimize_stack_ir(value _on) {
154+
CAMLparam1(_on);
155+
bool on = Bool_val(_on);
156+
BinaryenSetOptimizeStackIR(on);
157+
CAMLreturn(Val_unit);
158+
}
159+
70160
CAMLprim value
71161
caml_binaryen_get_pass_argument(value _name) {
72162
CAMLparam1(_name);
@@ -88,6 +178,36 @@ caml_binaryen_set_pass_argument(value _name, value _val) {
88178
CAMLreturn(Val_unit);
89179
}
90180

181+
CAMLprim value
182+
caml_binaryen_clear_pass_arguments(value unit) {
183+
CAMLparam1(unit);
184+
BinaryenClearPassArguments();
185+
CAMLreturn(Val_unit);
186+
}
187+
188+
CAMLprim value
189+
caml_binaryen_has_pass_to_skip(value _pass) {
190+
CAMLparam1(_pass);
191+
const char* pass = Safe_String_val(_pass);
192+
bool res = BinaryenHasPassToSkip(pass);
193+
CAMLreturn(Val_bool(res));
194+
}
195+
196+
CAMLprim value
197+
caml_binaryen_add_pass_to_skip(value _pass) {
198+
CAMLparam1(_pass);
199+
const char* pass = Safe_String_val(_pass);
200+
BinaryenAddPassToSkip(pass);
201+
CAMLreturn(Val_unit);
202+
}
203+
204+
CAMLprim value
205+
caml_binaryen_clear_passes_to_skip(value unit) {
206+
CAMLparam1(unit);
207+
BinaryenClearPassesToSkip();
208+
CAMLreturn(Val_unit);
209+
}
210+
91211
CAMLprim value
92212
caml_binaryen_get_always_inline_max_size(value unit) {
93213
CAMLparam1(unit);
@@ -133,6 +253,21 @@ caml_binaryen_set_one_caller_inline_max_size(value _size) {
133253
CAMLreturn(Val_unit);
134254
}
135255

256+
CAMLprim value
257+
caml_binaryen_get_allow_inlining_functions_with_loops(value unit) {
258+
CAMLparam1(unit);
259+
bool res = BinaryenGetAllowInliningFunctionsWithLoops();
260+
CAMLreturn(Val_bool(res));
261+
}
262+
263+
CAMLprim value
264+
caml_binaryen_set_allow_inlining_functions_with_loops(value _size) {
265+
CAMLparam1(_size);
266+
int on = Bool_val(_size);
267+
BinaryenSetAllowInliningFunctionsWithLoops(on);
268+
CAMLreturn(Val_unit);
269+
}
270+
136271
CAMLprim value
137272
caml_binaryen_set_colors_enabled(value _on) {
138273
CAMLparam1(_on);

src/settings.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ function caml_binaryen_set_debug_info(on) {
3636
return Binaryen._BinaryenSetDebugInfo(on);
3737
}
3838

39+
//Provides: caml_binaryen_get_traps_never_happen
40+
//Requires: Binaryen
41+
function caml_binaryen_get_traps_never_happen() {
42+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
43+
return Binaryen._BinaryenGetTrapsNeverHappen();
44+
}
45+
46+
//Provides: caml_binaryen_set_traps_never_happen
47+
//Requires: Binaryen
48+
function caml_binaryen_set_traps_never_happen(on) {
49+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
50+
return Binaryen._BinaryenSetTrapsNeverHappen(on);
51+
}
52+
53+
//Provides: caml_binaryen_get_closed_world
54+
//Requires: Binaryen
55+
function caml_binaryen_get_closed_world() {
56+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
57+
return Binaryen._BinaryenGetClosedWorld();
58+
}
59+
60+
//Provides: caml_binaryen_set_closed_world
61+
//Requires: Binaryen
62+
function caml_binaryen_set_closed_world(on) {
63+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
64+
return Binaryen._BinaryenSetClosedWorld(on);
65+
}
66+
3967
//Provides: caml_binaryen_get_low_memory_unused
4068
//Requires: Binaryen
4169
function caml_binaryen_get_low_memory_unused() {
@@ -50,6 +78,62 @@ function caml_binaryen_set_low_memory_unused(on) {
5078
return Binaryen._BinaryenSetLowMemoryUnused(on);
5179
}
5280

81+
//Provides: caml_binaryen_get_zero_filled_memory
82+
//Requires: Binaryen
83+
function caml_binaryen_get_zero_filled_memory() {
84+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
85+
return Binaryen._BinaryenGetZeroFilledMemory();
86+
}
87+
88+
//Provides: caml_binaryen_set_zero_filled_memory
89+
//Requires: Binaryen
90+
function caml_binaryen_set_zero_filled_memory(on) {
91+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
92+
return Binaryen._BinaryenSetZeroFilledMemory(on);
93+
}
94+
95+
//Provides: caml_binaryen_get_fast_math
96+
//Requires: Binaryen
97+
function caml_binaryen_get_fast_math() {
98+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
99+
return Binaryen._BinaryenGetFastMath();
100+
}
101+
102+
//Provides: caml_binaryen_set_fast_math
103+
//Requires: Binaryen
104+
function caml_binaryen_set_fast_math(on) {
105+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
106+
return Binaryen._BinaryenSetFastMath(on);
107+
}
108+
109+
//Provides: caml_binaryen_get_generate_stack_ir
110+
//Requires: Binaryen
111+
function caml_binaryen_get_generate_stack_ir() {
112+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
113+
return Binaryen._BinaryenGetGenerateStackIR();
114+
}
115+
116+
//Provides: caml_binaryen_set_generate_stack_ir
117+
//Requires: Binaryen
118+
function caml_binaryen_set_generate_stack_ir(on) {
119+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
120+
return Binaryen._BinaryenSetGenerateStackIR(on);
121+
}
122+
123+
//Provides: caml_binaryen_get_optimize_stack_ir
124+
//Requires: Binaryen
125+
function caml_binaryen_get_optimize_stack_ir() {
126+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
127+
return Binaryen._BinaryenGetOptimizeStackIR();
128+
}
129+
130+
//Provides: caml_binaryen_set_optimize_stack_ir
131+
//Requires: Binaryen
132+
function caml_binaryen_set_optimize_stack_ir(on) {
133+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
134+
return Binaryen._BinaryenSetOptimizeStackIR(on);
135+
}
136+
53137
//Provides: caml_binaryen_get_pass_argument
54138
//Requires: Binaryen
55139
//Requires: caml_jsstring_of_string
@@ -70,6 +154,39 @@ function caml_binaryen_set_pass_argument(name, value) {
70154
);
71155
}
72156

157+
//Provides: caml_binaryen_clear_pass_arguments
158+
//Requires: Binaryen
159+
function caml_binaryen_clear_pass_arguments() {
160+
return Binaryen.clearPassArguments();
161+
}
162+
163+
//Provides: caml_binaryen_has_pass_to_skip
164+
//Requires: Binaryen
165+
//Requires: caml_jsstring_of_string
166+
//Requires: caml_js_to_bool
167+
function caml_binaryen_has_pass_to_skip(pass) {
168+
return caml_js_to_bool(
169+
Binaryen.hasPassToSkip(
170+
caml_jsstring_of_string(pass)
171+
)
172+
);
173+
}
174+
175+
//Provides: caml_binaryen_add_pass_to_skip
176+
//Requires: Binaryen
177+
//Requires: caml_jsstring_of_string
178+
function caml_binaryen_add_pass_to_skip(pass) {
179+
return Binaryen.addPassToSkip(
180+
caml_jsstring_of_string(pass)
181+
);
182+
}
183+
184+
//Provides: caml_binaryen_clear_passes_to_skip
185+
//Requires: Binaryen
186+
function caml_binaryen_clear_passes_to_skip(pass) {
187+
return Binaryen.clearPassesToSkip();
188+
}
189+
73190
//Provides: caml_binaryen_get_always_inline_max_size
74191
//Requires: Binaryen
75192
function caml_binaryen_get_always_inline_max_size() {
@@ -106,6 +223,20 @@ function caml_binaryen_set_one_caller_inline_max_size(size) {
106223
return Binaryen.setOneCallerInlineMaxSize(size);
107224
}
108225

226+
//Provides: caml_binaryen_get_allow_inlining_functions_with_loops
227+
//Requires: Binaryen
228+
function caml_binaryen_get_allow_inlining_functions_with_loops() {
229+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
230+
return Binaryen._BinaryenGetAllowInliningFunctionsWithLoops();
231+
}
232+
233+
//Provides: caml_binaryen_set_allow_inlining_functions_with_loops
234+
//Requires: Binaryen
235+
function caml_binaryen_set_allow_inlining_functions_with_loops(on) {
236+
// Uses the `_Binaryen` function because then we are working with ints which are also booleans to JSOO
237+
return Binaryen._BinaryenSetAllowInliningFunctionsWithLoops(on);
238+
}
239+
109240
//Provides: caml_binaryen_set_colors_enabled
110241
//Requires: Binaryen
111242
function caml_binaryen_set_colors_enabled(on) {

src/settings.ml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,57 @@ external set_shrink_level : int -> unit = "caml_binaryen_set_shrink_level"
55
external get_debug_info : unit -> bool = "caml_binaryen_get_debug_info"
66
external set_debug_info : bool -> unit = "caml_binaryen_set_debug_info"
77

8+
external get_traps_never_happen : unit -> bool
9+
= "caml_binaryen_get_traps_never_happen"
10+
11+
external set_traps_never_happen : bool -> unit
12+
= "caml_binaryen_set_traps_never_happen"
13+
14+
external get_closed_world : unit -> bool = "caml_binaryen_get_closed_world"
15+
external set_closed_world : bool -> unit = "caml_binaryen_set_closed_world"
16+
817
external get_low_memory_unused : unit -> bool
918
= "caml_binaryen_get_low_memory_unused"
1019

1120
external set_low_memory_unused : bool -> unit
1221
= "caml_binaryen_set_low_memory_unused"
1322

23+
external get_zero_filled_memory : unit -> bool
24+
= "caml_binaryen_get_zero_filled_memory"
25+
26+
external set_zero_filled_memory : bool -> unit
27+
= "caml_binaryen_set_zero_filled_memory"
28+
29+
external get_fast_math : unit -> bool = "caml_binaryen_get_fast_math"
30+
external set_fast_math : bool -> unit = "caml_binaryen_set_fast_math"
31+
32+
external get_generate_stack_ir : unit -> bool
33+
= "caml_binaryen_get_generate_stack_ir"
34+
35+
external set_generate_stack_ir : bool -> unit
36+
= "caml_binaryen_set_generate_stack_ir"
37+
38+
external get_optimize_stack_ir : unit -> bool
39+
= "caml_binaryen_get_optimize_stack_ir"
40+
41+
external set_optimize_stack_ir : bool -> unit
42+
= "caml_binaryen_set_optimize_stack_ir"
43+
1444
external get_pass_argument : string -> string option
1545
= "caml_binaryen_get_pass_argument"
1646

1747
external set_pass_argument : string -> string -> unit
1848
= "caml_binaryen_set_pass_argument"
1949

50+
external clear_pass_arguments : unit -> unit
51+
= "caml_binaryen_clear_pass_arguments"
52+
53+
external has_pass_to_skip : string -> bool = "caml_binaryen_has_pass_to_skip"
54+
external add_pass_to_skip : string -> unit = "caml_binaryen_add_pass_to_skip"
55+
56+
external clear_passes_to_skip : unit -> unit
57+
= "caml_binaryen_clear_passes_to_skip"
58+
2059
external get_always_inline_max_size : unit -> int
2160
= "caml_binaryen_get_always_inline_max_size"
2261

@@ -35,5 +74,11 @@ external get_one_caller_inline_max_size : unit -> int
3574
external set_one_caller_inline_max_size : int -> unit
3675
= "caml_binaryen_set_one_caller_inline_max_size"
3776

77+
external get_allow_inlining_functions_with_loops : unit -> bool
78+
= "caml_binaryen_get_allow_inlining_functions_with_loops"
79+
80+
external set_allow_inlining_functions_with_loops : bool -> unit
81+
= "caml_binaryen_set_allow_inlining_functions_with_loops"
82+
3883
external set_colors_enabled : bool -> unit = "caml_binaryen_set_colors_enabled"
3984
external are_colors_enabled : unit -> bool = "caml_binaryen_are_colors_enabled"

0 commit comments

Comments
 (0)