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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
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
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
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
14 15 16 17 18 19 20 21 22 23 24 25 | |
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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
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.
Source code in xdsl/transforms/eqsat_add_costs.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |