jon.recoil.org

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 reason =
  1. | At_toplevel
  2. | Contains_static_consts
  3. | Contains_set_of_closures
type cost = {
  1. size_of_primitives : int;
}
type t = private
  1. | Can_specialize of Flambda2_simplify.Specialization_cost.cost
  2. | Cannot_specialize of {
    1. reason : Flambda2_simplify.Specialization_cost.reason;
    }

The current specialization status, stored in the dacc.

Printing function.

Creation

Create a Can_specialize value with zero intial cost.

Create a value preventing any specialization of the current continuation.

Updating Costs

Add a primitive of the given size to the cost of specialization

Add a set of closure containing ~num closures to the cost of specialization.