[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
This commit is contained in:
Ingo Müller
2023-07-17 10:26:33 +00:00
parent f62cb13fb2
commit 4f30746ca0
2 changed files with 57 additions and 0 deletions

View File

@@ -171,6 +171,37 @@ def testMergeHandlesOp():
# CHECK: = merge_handles %[[ARG1]]
@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
@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())