Module Flambda2_simplify.Specialization_cost
Continuation Specialization Cost
Continuation specialization is done in simplify on the way down. Consider a term of the form:
let_cont k x =
let_cont k' y =
...
in
..
switch x with
| 0 -> k' 0
| 1 -> k' 1
in
..
switch .. with
| 0 -> k 0
| 1 -> k 1The decision to specialize continuation k is made once Simplify has reached the bottom of the handler of k. This allows to know all of the relevant information before deciding whether to specialize k: all uses of k have been seen, and we have also seen the code for the handler of ĸ.
The type t represents an accumulator updated while doing the downwards pass on the handler of k to record enough information to estimate the cost of a specialization of k, and whether there was any reason to **not** specialize k regardless of the cost
The current specialization status, stored in the dacc.
val print : Format.formatter -> t -> unitPrinting function.
Creation
val can_specialize : tCreate a Can_specialize value with zero intial cost.
Create a value preventing any specialization of the current continuation.
Updating Costs
val add_prim :
machine_width:Target_system.Machine_width.t ->
Flambda2_terms.Flambda_primitive.t ->
t ->
tAdd a primitive of the given size to the cost of specialization
val add_set_of_closures : Flambda2_terms.Set_of_closures.t -> t -> tAdd a set of closure containing ~num closures to the cost of specialization.
val add_lifted_set_of_closures : Flambda2_terms.Set_of_closures.t -> t -> t