Skip to content

Commit 6ae87f9

Browse files
author
git apple-llvm automerger
committed
Merge commit '37b26bf48b98' from llvm.org/main into next
2 parents 84ae50e + 37b26bf commit 6ae87f9

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

mlir/include/mlir/Dialect/Transform/IR/TransformOps.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ def ApplyPatternsOp : TransformDialectOp<"apply_patterns",
331331
}];
332332

333333
let arguments = (ins
334-
TransformHandleTypeInterface:$target, UnitAttr:$apply_cse);
334+
TransformHandleTypeInterface:$target,
335+
UnitAttr:$apply_cse,
336+
DefaultValuedAttr<I64Attr, "static_cast<uint64_t>(-1)">:$max_iterations,
337+
DefaultValuedAttr<I64Attr, "static_cast<uint64_t>(-1)">:$max_num_rewrites);
335338
let results = (outs);
336339
let regions = (region MaxSizedRegion<1>:$patterns);
337340

mlir/lib/Dialect/Transform/IR/TransformOps.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ DiagnosedSilenceableFailure transform::ApplyPatternsOp::applyToOne(
396396
static_cast<RewriterBase::Listener *>(rewriter.getListener());
397397
FrozenRewritePatternSet frozenPatterns(std::move(patterns));
398398

399+
config.maxIterations = getMaxIterations() == static_cast<uint64_t>(-1)
400+
? GreedyRewriteConfig::kNoLimit
401+
: getMaxIterations();
402+
config.maxNumRewrites = getMaxNumRewrites() == static_cast<uint64_t>(-1)
403+
? GreedyRewriteConfig::kNoLimit
404+
: getMaxNumRewrites();
405+
399406
// Apply patterns and CSE repetitively until a fixpoint is reached. If no CSE
400407
// was requested, apply the greedy pattern rewrite only once. (The greedy
401408
// pattern rewrite driver already iterates to a fixpoint internally.)

mlir/test/Dialect/Transform/test-pattern-application.mlir

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,36 @@ module attributes {transform.with_named_sequence} {
2626

2727
// -----
2828

29+
// CHECK-LABEL: @limited_updates
30+
func.func @limited_updates() {
31+
"test.container"() ({
32+
// Only one is replaced.
33+
// CHECK: "test.foo"() {replace_with_new_op = "test.foo"}
34+
// CHECK: "test.foo"() : ()
35+
%0 = "test.foo"() {replace_with_new_op = "test.foo"} : () -> (i32)
36+
%1 = "test.foo"() {replace_with_new_op = "test.foo"} : () -> (i32)
37+
}) : () -> ()
38+
return
39+
}
40+
41+
module attributes {transform.with_named_sequence} {
42+
transform.named_sequence @__transform_main(%arg0: !transform.any_op) {
43+
// Pattern application will fail because of the upper limit, wrap in
44+
// sequence to suppress the error message.
45+
transform.sequence %arg0 : !transform.any_op failures(suppress) {
46+
^bb0(%arg1: !transform.any_op):
47+
%0 = transform.structured.match ops{["test.container"]} in %arg1 : (!transform.any_op) -> !transform.any_op
48+
%1 = transform.structured.match ops{["test.foo"]} in %arg1 : (!transform.any_op) -> !transform.any_op
49+
transform.apply_patterns to %0 {
50+
transform.apply_patterns.transform.test_patterns
51+
} {max_num_rewrites = 1} : !transform.any_op
52+
}
53+
transform.yield
54+
}
55+
}
56+
57+
// -----
58+
2959
func.func @replacement_op_not_found() {
3060
"test.container"() ({
3161
// expected-note @below {{[0] replaced op}}

0 commit comments

Comments
 (0)