Eqsat add costs
eqsat_add_costs
¶
EqsatAddCostsPass
dataclass
¶
Bases: ModulePass
Add costs to all operations in blocks that contain equivalence.class ops, and perform bottom-up extraction to find the minimum cost node in each e-class.
The cost of an e-class operation is determined through fixed-point iteration: - Each operand's total cost is calculated (own cost + dependency costs) - The operand with minimum total cost is selected and stored in min_cost_index
The cost for non-eclass operations is fetched from the cost_dict or set to the default value. The cost is stored as an IntAttr in the EQSAT_COST_LABEL attribute.
If the cost cannot be calculated, the default value can be provided with the
default optional parameter.
Source code in xdsl/transforms/eqsat_add_costs.py
name = 'eqsat-add-costs'
class-attribute
instance-attribute
¶
cost_file: str | None = field(default=None)
class-attribute
instance-attribute
¶
Path to JSON file of cost values
default: int | None = field(default=None)
class-attribute
instance-attribute
¶
Default cost to assign if it cannot be calculated.
__init__(cost_file: str | None = None, default: int | None = None) -> None
¶
apply(ctx: Context, op: builtin.ModuleOp) -> None
¶
Source code in xdsl/transforms/eqsat_add_costs.py
get_node_base_cost(op: Operation, default_cost: int | None) -> int | None
¶
Get the base cost of an operation (without considering dependencies).
Source code in xdsl/transforms/eqsat_add_costs.py
calculate_node_total_cost(value: SSAValue, eclass_costs: dict[OpResult, int], default_cost: int | None) -> int | None
¶
Calculate the total cost of a node: its own cost plus the costs of all its
e-class dependencies. This is equivalent to the Rust node_sum_cost function.
Uses dictionary lookup (not recursion) to get child e-class costs. Returns None if any dependency cost is unknown.
Source code in xdsl/transforms/eqsat_add_costs.py
add_eqsat_costs(block: Block, default: int | None, cost_dict: dict[str, int])
¶
Add costs to all operations and perform bottom-up extraction to find the minimum cost node in each e-class using fixed-point iteration.