Skip to content

Commit 45cca8d

Browse files
authored
Add flags for small and big function inlining threshold (#328)
Preparatory work for the inliner heuristics: - Functions with a cost less than the specified small threshold will always be inlined. - Functions with a cost greater than the specified big threshold will never be inlined.
1 parent b0ed465 commit 45cca8d

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

driver/compenv.ml

+10
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,16 @@ let read_one_param ppf position name v =
493493
| "flambda-debug-concrete-types-only-on-canonicals" ->
494494
set "flambda-debug-concrete-types-only-on-canonicals"
495495
[ Flambda.Debug.concrete_types_only_on_canonicals ] v
496+
| "flambda-expert-small-function-threshold" ->
497+
Int_arg_helper.parse v
498+
"Bad syntax in OCAMLPARAM for \
499+
'flambda-expert-small-function-threshold'"
500+
Flambda.Expert.small_function_threshold
501+
| "flambda-expert-big-function-threshold" ->
502+
Int_arg_helper.parse v
503+
"Bad syntax in OCAMLPARAM for \
504+
'flambda-expert-big-function-threshold'"
505+
Flambda.Expert.big_function_threshold
496506
| _ ->
497507
if not (List.mem name !can_discard) then begin
498508
can_discard := name :: !can_discard;

driver/main_args.ml

+34
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,20 @@ let mk_flambda_expert_max_inlining_depth f =
988988
" Set maximum inlining depth"
989989
;;
990990

991+
let mk_flambda_expert_small_function_threshold f =
992+
"-flambda-expert-small-function-threshold", Arg.String f,
993+
Printf.sprintf "<n>|<round>=<n>[,...] Functions with a cost less than this \
994+
threshold will always be inlined (default %d)."
995+
Clflags.Flambda.Expert.default_small_function_threshold
996+
;;
997+
998+
let mk_flambda_expert_big_function_threshold f =
999+
"-flambda-expert-big-function-threshold", Arg.String f,
1000+
Printf.sprintf "<n>|<round>=<n>[,...] Functions with a cost greater than this \
1001+
threshold will never be inlined (default %d)."
1002+
Clflags.Flambda.Expert.default_big_function_threshold
1003+
;;
1004+
9911005
let mk_flambda_expert_max_block_size_for_projections f =
9921006
"-flambda-expert-max-block-size-for-projections", Arg.Int f,
9931007
" Do not simplify projections from blocks if the block size exceeds \
@@ -1252,6 +1266,8 @@ module type Optcommon_options = sig
12521266
val _flambda_expert_phantom_lets : unit -> unit
12531267
val _no_flambda_expert_phantom_lets : unit -> unit
12541268
val _flambda_expert_max_inlining_depth : int -> unit
1269+
val _flambda_expert_small_function_threshold : string -> unit
1270+
val _flambda_expert_big_function_threshold : string -> unit
12551271
val _flambda_expert_max_block_size_for_projections : int -> unit
12561272
val _flambda_debug_permute_every_name : unit -> unit
12571273
val _no_flambda_debug_permute_every_name : unit -> unit
@@ -1618,6 +1634,10 @@ struct
16181634
F._no_flambda_expert_phantom_lets;
16191635
mk_flambda_expert_max_inlining_depth
16201636
F._flambda_expert_max_inlining_depth;
1637+
mk_flambda_expert_small_function_threshold
1638+
F._flambda_expert_small_function_threshold;
1639+
mk_flambda_expert_big_function_threshold
1640+
F._flambda_expert_big_function_threshold;
16211641
mk_flambda_expert_max_block_size_for_projections
16221642
F._flambda_expert_max_block_size_for_projections;
16231643
mk_flambda_debug_permute_every_name
@@ -1782,6 +1802,10 @@ module Make_opttop_options (F : Opttop_options) = struct
17821802
F._no_flambda_expert_phantom_lets;
17831803
mk_flambda_expert_max_inlining_depth
17841804
F._flambda_expert_max_inlining_depth;
1805+
mk_flambda_expert_small_function_threshold
1806+
F._flambda_expert_small_function_threshold;
1807+
mk_flambda_expert_big_function_threshold
1808+
F._flambda_expert_big_function_threshold;
17851809
mk_flambda_expert_max_block_size_for_projections
17861810
F._flambda_expert_max_block_size_for_projections;
17871811
mk_flambda_debug_permute_every_name
@@ -2096,6 +2120,16 @@ module Default = struct
20962120
clear Flambda.Expert.phantom_lets
20972121
let _flambda_expert_max_inlining_depth depth =
20982122
Flambda.Expert.max_inlining_depth := depth
2123+
let _flambda_expert_small_function_threshold spec =
2124+
Int_arg_helper.parse spec
2125+
"Syntax: -flambda-expert-small-function-threshold <n> | \
2126+
<round>=<n>[,...]"
2127+
Flambda.Expert.small_function_threshold
2128+
let _flambda_expert_big_function_threshold spec =
2129+
Int_arg_helper.parse spec
2130+
"Syntax: -flambda-expert-big-function-threshold <n> | \
2131+
<round>=<n>[,...]"
2132+
Flambda.Expert.big_function_threshold
20992133
let _flambda_expert_max_block_size_for_projections size =
21002134
Flambda.Expert.max_block_size_for_projections := Some size
21012135
let _flambda_debug_permute_every_name =

driver/main_args.mli

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ module type Optcommon_options = sig
243243
val _flambda_expert_phantom_lets : unit -> unit
244244
val _no_flambda_expert_phantom_lets : unit -> unit
245245
val _flambda_expert_max_inlining_depth : int -> unit
246+
val _flambda_expert_small_function_threshold : string -> unit
247+
val _flambda_expert_big_function_threshold : string -> unit
246248
val _flambda_expert_max_block_size_for_projections : int -> unit
247249
val _flambda_debug_permute_every_name : unit -> unit
248250
val _no_flambda_debug_permute_every_name : unit -> unit

utils/clflags.ml

+8
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ module Flambda = struct
439439
let phantom_lets = ref true
440440
let max_inlining_depth = ref 1
441441
let max_block_size_for_projections = ref None
442+
443+
let default_small_function_threshold = 128
444+
let default_big_function_threshold = 65536
445+
446+
let small_function_threshold =
447+
ref (Int_arg_helper.default default_small_function_threshold)
448+
let big_function_threshold =
449+
ref (Int_arg_helper.default default_big_function_threshold)
442450
end
443451

444452
module Debug = struct

utils/clflags.mli

+4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ module Flambda : sig
258258
val inline_effects_in_cmm : bool ref
259259
val phantom_lets : bool ref
260260
val max_inlining_depth : int ref
261+
val default_small_function_threshold : int
262+
val default_big_function_threshold : int
263+
val small_function_threshold : Int_arg_helper.parsed ref
264+
val big_function_threshold : Int_arg_helper.parsed ref
261265
val max_block_size_for_projections : int option ref
262266
end
263267

0 commit comments

Comments
 (0)