mlir._mlir_libs._mlir.rewrite

Classes

Functions

apply_patterns_and_fold_greedily(…)

Applys the given patterns to the given op greedily while folding results.

walk_and_apply_patterns(→ None)

Applies the given patterns to the given op by a fast walk-based driver.

Module Contents

class mlir._mlir_libs._mlir.rewrite.GreedyRewriteStrictness

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

ANY_OP = 0
EXISTING_AND_NEW_OPS = 1
EXISTING_OPS = 2
class mlir._mlir_libs._mlir.rewrite.GreedySimplifyRegionLevel

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

DISABLED = 0
NORMAL = 1
AGGRESSIVE = 2
class mlir._mlir_libs._mlir.rewrite.PatternRewriter
property ip: _mlir.ir.InsertionPoint

The current insertion point of the PatternRewriter.

replace_op(op: _mlir.ir._OperationBase, new_op: _mlir.ir._OperationBase) None
replace_op(op: _mlir.ir._OperationBase, values: collections.abc.Sequence[_mlir.ir.Value]) None

Replace an operation with a list of values.

erase_op(op: _mlir.ir.Operation) None

Erase an operation.

class mlir._mlir_libs._mlir.rewrite.RewritePatternSet(context: Context | None = None)
add(root: type | str, fn: collections.abc.Callable[[mlir.ir.Operation, PatternRewriter], Any], benefit: int = 1) None

Add a new rewrite pattern on the specified root operation, using the provided callable for matching and rewriting, and assign it the given benefit.

Parameters:
  • root – The root operation to which this pattern applies. This may be either an OpView subclass (e.g., arith.AddIOp) or an operation name string (e.g., "arith.addi").

  • fn – The callable to use for matching and rewriting, which takes an operation and a pattern rewriter as arguments. The match is considered successful iff the callable returns a value where bool(value) is False (e.g. None). If possible, the operation is cast to its corresponding OpView subclass before being passed to the callable.

  • benefit – The benefit of the pattern, defaulting to 1.

freeze() FrozenRewritePatternSet

Freeze the pattern set into a frozen one.

class mlir._mlir_libs._mlir.rewrite.PDLResultList
append(arg: _mlir.ir.Value, /) None
append(arg: _mlir.ir.Operation, /) None
append(arg: _mlir.ir.Type, /) None
append(arg: _mlir.ir.Attribute, /) None
class mlir._mlir_libs._mlir.rewrite.PDLModule(module: _mlir.ir.Module)
class mlir._mlir_libs._mlir.rewrite.PDLModule(module: _mlir.ir.Module)
freeze() FrozenRewritePatternSet
register_rewrite_function(arg0: str, arg1: collections.abc.Callable, /) None
register_constraint_function(arg0: str, arg1: collections.abc.Callable, /) None
class mlir._mlir_libs._mlir.rewrite.GreedyRewriteConfig
property max_iterations: int

Maximum number of iterations

property max_num_rewrites: int

Maximum number of rewrites per iteration

property use_top_down_traversal: bool

Whether to use top-down traversal

property enable_folding: bool

Enable or disable folding

property strictness: GreedyRewriteStrictness

Rewrite strictness level

property region_simplification_level: GreedySimplifyRegionLevel

Region simplification level

property enable_constant_cse: bool

Enable or disable constant CSE

class mlir._mlir_libs._mlir.rewrite.FrozenRewritePatternSet
property _CAPIPtr: object
_CAPICreate() object
mlir._mlir_libs._mlir.rewrite.apply_patterns_and_fold_greedily(module: _mlir.ir.Module, set: FrozenRewritePatternSet, config: GreedyRewriteConfig | None = None) None
mlir._mlir_libs._mlir.rewrite.apply_patterns_and_fold_greedily(op: _mlir.ir._OperationBase, set: FrozenRewritePatternSet, config: GreedyRewriteConfig | None = None) None

Applys the given patterns to the given op greedily while folding results.

mlir._mlir_libs._mlir.rewrite.walk_and_apply_patterns(op: _mlir.ir._OperationBase, set: FrozenRewritePatternSet) None

Applies the given patterns to the given op by a fast walk-based driver.