Module Flambda2_simplify.Specialization_cost
ontinuation 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 1
The 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
type t = private | Can_specialize of Flambda2_simplify.Specialization_cost.cost| Cannot_specialize of {}
The current specialization status, stored in the dacc.
val print :
Stdlib.Format.formatter ->
Flambda2_simplify.Specialization_cost.t ->
unitPrinting function.
Creation
val can_specialize : Flambda2_simplify.Specialization_cost.tCreate a Can_specialize value with zero intial cost.
val cannot_specialize :
Flambda2_simplify.Specialization_cost.reason ->
Flambda2_simplify.Specialization_cost.tCreate 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 ->
Flambda2_simplify.Specialization_cost.t ->
Flambda2_simplify.Specialization_cost.tAdd a primitive of the given size to the cost of specialization
val add_set_of_closures :
Flambda2_terms.Set_of_closures.t ->
Flambda2_simplify.Specialization_cost.t ->
Flambda2_simplify.Specialization_cost.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 ->
Flambda2_simplify.Specialization_cost.t ->
Flambda2_simplify.Specialization_cost.t