[Mlir-commits] [mlir] 4f30746 - [mlir][transform][python] Add extended ApplyPatternsOp.
Ingo Müller
llvmlistbot at llvm.org
Thu Jul 20 07:20:58 PDT 2023
Author: Ingo Müller
Date: 2023-07-20T14:20:50Z
New Revision: 4f30746ca006f91daa6e84d126c11545ecaf195e
URL: https://github.com/llvm/llvm-project/commit/4f30746ca006f91daa6e84d126c11545ecaf195e
DIFF: https://github.com/llvm/llvm-project/commit/4f30746ca006f91daa6e84d126c11545ecaf195e.diff
LOG: [mlir][transform][python] Add extended ApplyPatternsOp.
This patch adds a mixin for ApplyPatternsOp to _transform_ops_ext.py
with syntactic sugar for construction such ops. Curiously, the op did
not have any constructors yet, probably because its tablegen definition
said to skip the default builders. The new constructor is thus quite
straightforward. The commit also adds a refined `region` property which
returns the first block of the single region.
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D155435
Added:
Modified:
mlir/python/mlir/dialects/_transform_ops_ext.py
mlir/test/python/dialects/transform.py
Removed:
################################################################################
diff --git a/mlir/python/mlir/dialects/_transform_ops_ext.py b/mlir/python/mlir/dialects/_transform_ops_ext.py
index 87f8d398cd5bfc..0db2e3bd93a3aa 100644
--- a/mlir/python/mlir/dialects/_transform_ops_ext.py
+++ b/mlir/python/mlir/dialects/_transform_ops_ext.py
@@ -29,6 +29,32 @@ def __init__(
)
+class ApplyPatternsOp:
+
+ def __init__(
+ self,
+ target: Union[Operation, Value, OpView],
+ *,
+ loc=None,
+ ip=None,
+ ):
+ operands = []
+ operands.append(_get_op_result_or_value(target))
+ super().__init__(
+ self.build_generic(attributes={},
+ results=[],
+ operands=operands,
+ successors=None,
+ regions=None,
+ loc=loc,
+ ip=ip))
+ self.regions[0].blocks.append()
+
+ @property
+ def patterns(self) -> Block:
+ return self.regions[0].blocks[0]
+
+
class testGetParentOp:
def __init__(
diff --git a/mlir/test/python/dialects/transform.py b/mlir/test/python/dialects/transform.py
index 668e0040d6b9c5..3e7e29a9c5b924 100644
--- a/mlir/test/python/dialects/transform.py
+++ b/mlir/test/python/dialects/transform.py
@@ -171,6 +171,37 @@ def testMergeHandlesOp():
# CHECK: = merge_handles %[[ARG1]]
+ at run
+def testApplyPatternsOpCompact():
+ sequence = transform.SequenceOp(
+ transform.FailurePropagationMode.PROPAGATE, [], transform.AnyOpType.get()
+ )
+ with InsertionPoint(sequence.body):
+ with InsertionPoint(transform.ApplyPatternsOp(sequence.bodyTarget).patterns):
+ transform.ApplyCanonicalizationPatternsOp()
+ transform.YieldOp()
+ # CHECK-LABEL: TEST: testApplyPatternsOpCompact
+ # CHECK: apply_patterns to
+ # CHECK: transform.apply_patterns.canonicalization
+ # CHECK: !transform.any_op
+
+
+ at run
+def testApplyPatternsOpWithType():
+ sequence = transform.SequenceOp(
+ transform.FailurePropagationMode.PROPAGATE, [],
+ transform.OperationType.get('test.dummy')
+ )
+ with InsertionPoint(sequence.body):
+ with InsertionPoint(transform.ApplyPatternsOp(sequence.bodyTarget).patterns):
+ transform.ApplyCanonicalizationPatternsOp()
+ transform.YieldOp()
+ # CHECK-LABEL: TEST: testApplyPatternsOp
+ # CHECK: apply_patterns to
+ # CHECK: transform.apply_patterns.canonicalization
+ # CHECK: !transform.op<"test.dummy">
+
+
@run
def testReplicateOp():
with_pdl = transform_pdl.WithPDLPatternsOp(transform.AnyOpType.get())
More information about the Mlir-commits
mailing list