mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
[MLIR][Transform][Python] transform.foreach wrapper and .owner OpViews (#172228)
Friendlier wrapper for transform.foreach. To facilitate that friendliness, makes it so that OpResult.owner returns the relevant OpView instead of Operation. For good measure, also changes Value.owner to return OpView instead of Operation, thereby ensuring consistency. That is, makes it is so that all op-returning .owner accessors return OpView (and thereby give access to all goodies available on registered OpViews.) Reland of #171544 due to fixup for integration test.
This commit is contained in:
@@ -401,3 +401,55 @@ def testApplyRegisteredPassOp(module: Module):
|
||||
options={"exclude": (symbol_a, symbol_b)},
|
||||
)
|
||||
transform.YieldOp()
|
||||
|
||||
|
||||
# CHECK-LABEL: TEST: testForeachOp
|
||||
@run
|
||||
def testForeachOp(module: Module):
|
||||
# CHECK: transform.sequence
|
||||
sequence = transform.SequenceOp(
|
||||
transform.FailurePropagationMode.Propagate,
|
||||
[transform.AnyOpType.get()],
|
||||
transform.AnyOpType.get(),
|
||||
)
|
||||
with InsertionPoint(sequence.body):
|
||||
# CHECK: {{.*}} = foreach %{{.*}} : !transform.any_op -> !transform.any_op
|
||||
foreach1 = transform.ForeachOp(
|
||||
(transform.AnyOpType.get(),), (sequence.bodyTarget,)
|
||||
)
|
||||
with InsertionPoint(foreach1.body):
|
||||
# CHECK: transform.yield {{.*}} : !transform.any_op
|
||||
transform.yield_(foreach1.bodyTargets)
|
||||
|
||||
a_val = transform.get_operand(
|
||||
transform.AnyValueType.get(), foreach1.result, [0]
|
||||
)
|
||||
a_param = transform.param_constant(
|
||||
transform.AnyParamType.get(), StringAttr.get("a_param")
|
||||
)
|
||||
|
||||
# CHECK: {{.*}} = foreach %{{.*}}, %{{.*}}, %{{.*}} : !transform.any_op, !transform.any_value, !transform.any_param -> !transform.any_value, !transform.any_param
|
||||
foreach2 = transform.foreach(
|
||||
(transform.AnyValueType.get(), transform.AnyParamType.get()),
|
||||
(sequence.bodyTarget, a_val, a_param),
|
||||
)
|
||||
with InsertionPoint(foreach2.owner.body):
|
||||
# CHECK: transform.yield {{.*}} : !transform.any_value, !transform.any_param
|
||||
transform.yield_(foreach2.owner.bodyTargets[1:3])
|
||||
|
||||
another_param = transform.param_constant(
|
||||
transform.AnyParamType.get(), StringAttr.get("another_param")
|
||||
)
|
||||
params = transform.merge_handles([a_param, another_param])
|
||||
|
||||
# CHECK: {{.*}} = foreach %{{.*}}, %{{.*}}, %{{.*}} with_zip_shortest : !transform.any_op, !transform.any_param, !transform.any_param -> !transform.any_op
|
||||
foreach3 = transform.foreach(
|
||||
(transform.AnyOpType.get(),),
|
||||
(foreach1.result, foreach2[1], params),
|
||||
with_zip_shortest=True,
|
||||
)
|
||||
with InsertionPoint(foreach3.owner.body):
|
||||
# CHECK: transform.yield {{.*}} : !transform.any_op
|
||||
transform.yield_((foreach3.owner.bodyTargets[0],))
|
||||
|
||||
transform.yield_((foreach3,))
|
||||
|
||||
@@ -174,7 +174,7 @@ def get_pdl_pattern_fold():
|
||||
|
||||
def is_zero(value):
|
||||
op = value.owner
|
||||
if isinstance(op, Operation):
|
||||
if isinstance(op, OpView):
|
||||
return op.name == "myint.constant" and op.attributes["value"].value == 0
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user