Bases: RewritePattern
Removes redundant allocations of empty tensors with no uses other than passed
as iter_arg to csl_stencil.apply. Prefer re-use where possible.
Source code in xdsl/transforms/canonicalization_patterns/csl_stencil.py
| class RedundantAccumulatorInitialisation(RewritePattern):
"""
Removes redundant allocations of empty tensors with no uses other than passed
as `iter_arg` to `csl_stencil.apply`. Prefer re-use where possible.
"""
@op_type_rewrite_pattern
def match_and_rewrite(
self, op: csl_stencil.ApplyOp, rewriter: PatternRewriter
) -> None:
if op.accumulator.has_more_than_one_use():
return
next_apply = op
while (next_apply := next_apply.next_op) is not None:
if (
isinstance(next_apply, csl_stencil.ApplyOp)
and next_apply.accumulator.has_one_use()
and isinstance(next_apply.accumulator, OpResult)
and isinstance(next_apply.accumulator.op, tensor.EmptyOp)
and op.accumulator.type == next_apply.accumulator.type
):
rewriter.replace(next_apply.accumulator.op, [], [op.accumulator])
|
Source code in xdsl/transforms/canonicalization_patterns/csl_stencil.py
| @op_type_rewrite_pattern
def match_and_rewrite(
self, op: csl_stencil.ApplyOp, rewriter: PatternRewriter
) -> None:
if op.accumulator.has_more_than_one_use():
return
next_apply = op
while (next_apply := next_apply.next_op) is not None:
if (
isinstance(next_apply, csl_stencil.ApplyOp)
and next_apply.accumulator.has_one_use()
and isinstance(next_apply.accumulator, OpResult)
and isinstance(next_apply.accumulator.op, tensor.EmptyOp)
and op.accumulator.type == next_apply.accumulator.type
):
rewriter.replace(next_apply.accumulator.op, [], [op.accumulator])
|