Varith transformations
varith_transformations
ARITH_TO_VARITH_TYPE_MAP: dict[type[arith.SignlessIntegerBinaryOperation | arith.FloatingPointLikeBinaryOperation], type[varith.VarithOp]] = {arith.AddiOp: varith.VarithAddOp, arith.AddfOp: varith.VarithAddOp, arith.MuliOp: varith.VarithMulOp, arith.MulfOp: varith.VarithMulOp}
module-attribute
ARITH_TYPES: dict[tuple[Literal['float', 'int'], Literal['add', 'mul']], type[arith.SignlessIntegerBinaryOperation | arith.FloatingPointLikeBinaryOperation]] = {('int', 'add'): arith.AddiOp, ('int', 'mul'): arith.MuliOp, ('float', 'add'): arith.AddfOp, ('float', 'mul'): arith.MulfOp}
module-attribute
ArithToVarithPattern
Bases: RewritePattern
Merges two arith operations into a varith operation.
Source code in xdsl/transforms/varith_transformations.py
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 | |
match_and_rewrite(op: arith.AddiOp | arith.AddfOp | arith.MuliOp | arith.MulfOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/varith_transformations.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
VarithToArithPattern
Bases: RewritePattern
Splits a varith operation into a sequence of arith operations.
Source code in xdsl/transforms/varith_transformations.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
match_and_rewrite(op: varith.VarithOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/varith_transformations.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
MergeVarithOpsPattern
Bases: RewritePattern
Looks at every operand to a varith op, and merges them into it if possible.
e.g. a varith.add(arith.addi(1,2), varith.add(3, 4, 5), 6) becomes a varith.add(1,2,3,4,5,6)
Source code in xdsl/transforms/varith_transformations.py
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 138 139 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 | |
match_and_rewrite(op: varith.VarithOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/varith_transformations.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 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 | |
FuseRepeatedAddArgsPattern
dataclass
Bases: RewritePattern
Prefer operand * count(operand) over repeated addition of operand.
The minimum count to trigger this rewrite can be specified in min_reps.
Source code in xdsl/transforms/varith_transformations.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
min_reps: int
instance-attribute
Minimum repetitions of operand to trigger fusion.
__init__(min_reps: int) -> None
match_and_rewrite(op: varith.VarithAddOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/varith_transformations.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
fuse(arg: SSAValue, count: int, t: builtin.IntegerType | builtin.IndexType | builtin.AnyFloat)
staticmethod
Source code in xdsl/transforms/varith_transformations.py
214 215 216 217 218 219 220 221 222 223 224 225 226 | |
ConvertArithToVarithPass
dataclass
Bases: ModulePass
Convert chains of arith.{add|mul}{i,f} operations into a single long variadic add or mul operation.
Used for simplifying arithmetic operations for rewrites that need to either change the order or completely "cut an equation in half".
Source code in xdsl/transforms/varith_transformations.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
name = 'convert-arith-to-varith'
class-attribute
instance-attribute
apply(ctx: Context, op: builtin.ModuleOp) -> None
Source code in xdsl/transforms/varith_transformations.py
239 240 241 242 243 244 245 246 247 248 | |
ConvertVarithToArithPass
dataclass
Bases: ModulePass
Convert a single long variadic add or mul operation into a chain of arith.{add|mul}{i,f} operations. Reverses ConvertArithToVarithPass.
Source code in xdsl/transforms/varith_transformations.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
name = 'convert-varith-to-arith'
class-attribute
instance-attribute
apply(ctx: Context, op: builtin.ModuleOp) -> None
Source code in xdsl/transforms/varith_transformations.py
260 261 262 263 264 | |
VarithFuseRepeatedOperandsPass
dataclass
Bases: ModulePass
Fuses several occurrences of the same operand into one.
Source code in xdsl/transforms/varith_transformations.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
name = 'varith-fuse-repeated-operands'
class-attribute
instance-attribute
min_reps: int = 2
class-attribute
instance-attribute
The minimum number of times an operand needs to be repeated before being fused.
apply(ctx: Context, op: builtin.ModuleOp) -> None
Source code in xdsl/transforms/varith_transformations.py
277 278 279 280 281 | |
is_integer_like_type(t: Attribute) -> bool
Returns true if t is an integer/container of integers/container of container of integers ...
Source code in xdsl/transforms/varith_transformations.py
173 174 175 176 177 178 179 | |