Template Function sequant::opt::extract_persistent_subexpressions

Function Documentation

template<std::ranges::range VectorLike, std::regular_invocable<ExprPtr> Transformer>
std::vector<std::size_t> sequant::opt::extract_persistent_subexpressions(VectorLike &expr_trees, const std::function<bool(const std::ranges::range_value_t<VectorLike>&)> &is_volatile_leaf, const Transformer &expr_to_tree, const std::function<std::string(const std::ranges::range_value_t<VectorLike>&, std::size_t)> &label_gen, std::size_t min_tensors = 2)

Replaces all maximal subtrees that are “persistent” by intermediates, no matter how often they are used. A subtree is persistent if none of its leaves is volatile and if it contains at least min_tensors tensors. Definitions of the intermediates are inserted into the given container right before their first use.

Parameters:
  • expr_trees – Container (vector-like) of evaluation trees

  • is_volatile_leaf – Predicate that identifies leaves that are not persistent

  • expr_to_tree – See eliminate_common_subexpressions

  • label_gen – Generates the label of an intermediate from its tree and a counter

  • min_tensors – The minimum number of tensors a persistent subtree must contain in order to be extracted (see also min_usage_filter)

Returns:

The positions of the inserted intermediate definitions