Skip to content

Commit c177350

Browse files
authored
[mlir] transform.structured.match loop-like flag (#65336)
Add an enum option to `transform.structured.match` operation to match payload operations implementing LoopLikeOpInterface.
1 parent c5cf4f7 commit c177350

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformEnums.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ include "mlir/IR/EnumAttr.td"
33
def MatchInterfaceEnum : I32EnumAttr<"MatchInterfaceEnum", "An interface to match",
44
[
55
I32EnumAttrCase<"LinalgOp", 0>,
6-
I32EnumAttrCase<"TilingInterface", 1>
6+
I32EnumAttrCase<"TilingInterface", 1>,
7+
I32EnumAttrCase<"LoopLikeInterface", 2>,
78
]>{
89
let cppNamespace = "mlir::transform";
910
}

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,9 @@ transform::MatchOp::apply(transform::TransformRewriter &rewriter,
11471147
if (iface == transform::MatchInterfaceEnum::TilingInterface &&
11481148
isa<TilingInterface>(op))
11491149
return;
1150+
if (iface == transform::MatchInterfaceEnum::LoopLikeInterface &&
1151+
!isa<LoopLikeOpInterface>(op))
1152+
return;
11501153
}
11511154

11521155
// Check if all specified attributes match.

mlir/test/Dialect/Linalg/transform-op-match.mlir

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,32 @@ transform.sequence failures(propagate) {
7676
// expected-remark @below {{0}}
7777
transform.test_print_number_of_associated_payload_ir_ops %no_match : !transform.any_op
7878
}
79+
80+
// -----
81+
82+
func.func private @callee()
83+
84+
func.func @foo(%lb: index, %ub: index, %step: index) {
85+
// expected-remark @below {{loop-like}}
86+
scf.for %i = %lb to %ub step %step {
87+
func.call @callee() : () -> ()
88+
scf.yield
89+
}
90+
// expected-remark @below {{loop-like}}
91+
scf.parallel (%i) = (%lb) to (%ub) step (%step) {
92+
func.call @callee() : () -> ()
93+
scf.yield
94+
}
95+
// expected-remark @below {{loop-like}}
96+
scf.forall (%i) in (%ub) {
97+
func.call @callee() : () -> ()
98+
}
99+
return
100+
}
101+
102+
transform.sequence failures(propagate) {
103+
^bb0(%arg0: !transform.any_op):
104+
%matched = transform.structured.match interface{LoopLikeInterface} in %arg0 : (!transform.any_op) -> !transform.any_op
105+
transform.test_print_remark_at_operand %matched, "loop-like" : !transform.any_op
106+
transform.yield
107+
}

0 commit comments

Comments
 (0)