Template Function sequant::opt::recycle_intermediate_names

Function Documentation

template<std::ranges::random_access_range VectorLike, typename Transformer>
NameRecyclingResult sequant::opt::recycle_intermediate_names(VectorLike &trees, const Transformer &expr_to_tree, const NameRecyclingOptions<std::ranges::range_value_t<VectorLike>> &opts)

Renames intermediates in the given sequence of evaluation trees such that names (and thereby storage) of intermediates that are no longer needed are reused for later intermediates of compatible shape.

The trees are interpreted as a program that is executed in the given order, where every tree computes its result (the root’s Tensor or Variable) from its leaves. Every value of a recyclable intermediate (see NameRecyclingOptions::is_recyclable and NameRecyclingOptions::starts_new_value) is given a new name, which is either recycled from a value whose last use precedes the value’s first definition or freshly generated. Names of all other objects are left untouched and are never generated as fresh names. Leaves referring to a recyclable intermediate are associated with the most recent value of that object defined by a previous tree.

Note

Uses are associated with definitions purely by their order in trees. In particular, loop-carried uses of recyclable intermediates within NameRecyclingOptions::repeated_regions are not supported.

Note

The trees must not be reordered afterwards as that may invalidate the liveness analysis performed by this function. Furthermore, the same name can refer to different values in the result. Anything identifying objects by name (e.g. common subexpression elimination) must therefore not be applied to the result.

Parameters:
  • trees – Random-access range of evaluation trees, each representing a ResultExpr

  • expr_to_tree – Functor that can convert ResultExpr objects into evaluation trees

  • opts – The options to use

Returns:

Statistics about the renaming