mlir._mlir_libs._mlir.rewrite

MLIR Rewrite Bindings

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.

apply_partial_conversion(→ None)

Applies a partial conversion on the given operation.

apply_full_conversion(→ None)

Applies a full conversion on the given operation.

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.DialectConversionFoldingMode

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

NEVER = 0
BEFORE_PATTERNS = 1
AFTER_PATTERNS = 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.

add_conversion(root: object, fn: collections.abc.Callable, type_converter: TypeConverter, benefit: int = 1) None

Add a new conversion 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, its adaptor, the type converter 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.

  • type_converter – The type converter to convert types in the IR.

  • 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.ConversionPatternRewriter

Bases: PatternRewriter

class mlir._mlir_libs._mlir.rewrite.ConversionTarget(context: Context | None = None)

Mark the given operations as legal.

add_illegal_op(*ops) None

Mark the given operations as illegal.

Mark the given dialects as legal.

add_illegal_dialect(*dialects) None

Mark the given dialect as illegal.

class mlir._mlir_libs._mlir.rewrite.TypeConverter
add_conversion(convert: collections.abc.Callable) None

Register a type conversion function.

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.ConversionConfig
property folding_mode: DialectConversionFoldingMode

folding behavior during dialect conversion

property build_materializations: bool

Whether the dialect conversion attempts to build source/target materializations

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.

mlir._mlir_libs._mlir.rewrite.apply_partial_conversion(op: _mlir.ir._OperationBase, target: ConversionTarget, set: FrozenRewritePatternSet, config: ConversionConfig | None = None) None

Applies a partial conversion on the given operation.

mlir._mlir_libs._mlir.rewrite.apply_full_conversion(op: _mlir.ir._OperationBase, target: ConversionTarget, set: FrozenRewritePatternSet, config: ConversionConfig | None = None) None

Applies a full conversion on the given operation.