Skip to content

Commit 519663b

Browse files
committed
[MLIR] Add an option to disable maxIterations in greedy pattern rewrites
This option is needed for passes that are known to reach a fix point, but may need many iterations depending on the size of the input IR. Differential Revision: https://reviews.llvm.org/D111058
1 parent 10b93a5 commit 519663b

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ class GreedyRewriteConfig {
3333
bool enableRegionSimplification = true;
3434

3535
/// This specifies the maximum number of times the rewriter will iterate
36-
/// between applying patterns and simplifying regions.
37-
unsigned maxIterations = 10;
36+
/// between applying patterns and simplifying regions. Use `kNoIterationLimit`
37+
/// to disable this iteration limit.
38+
int64_t maxIterations = 10;
39+
40+
static constexpr int64_t kNoIterationLimit = -1;
3841
};
3942

4043
//===----------------------------------------------------------------------===//

mlir/include/mlir/Transforms/Passes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def Canonicalizer : Pass<"canonicalize"> {
378378
Option<"enableRegionSimplification", "region-simplify", "bool",
379379
/*default=*/"true",
380380
"Seed the worklist in general top-down order">,
381-
Option<"maxIterations", "max-iterations", "unsigned",
381+
Option<"maxIterations", "max-iterations", "int64_t",
382382
/*default=*/"10",
383383
"Seed the worklist in general top-down order">
384384
] # RewritePassUtils.options;

mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ bool GreedyPatternRewriteDriver::simplify(MutableArrayRef<Region> regions) {
222222
// is kept up to date.
223223
if (config.enableRegionSimplification)
224224
changed |= succeeded(simplifyRegions(*this, regions));
225-
} while (changed && ++iteration < config.maxIterations);
225+
} while (changed &&
226+
(++iteration < config.maxIterations ||
227+
config.maxIterations == GreedyRewriteConfig::kNoIterationLimit));
226228

227229
// Whether the rewrite converges, i.e. wasn't changed in the last iteration.
228230
return !changed;
@@ -345,7 +347,9 @@ LogicalResult OpPatternRewriteDriver::simplifyLocally(Operation *op,
345347
changed |= succeeded(matcher.matchAndRewrite(op, *this));
346348
if ((erased = opErasedViaPatternRewrites))
347349
return success();
348-
} while (changed && ++iterations < maxIterations);
350+
} while (changed &&
351+
(++iterations < maxIterations ||
352+
maxIterations == GreedyRewriteConfig::kNoIterationLimit));
349353

350354
// Whether the rewrite converges, i.e. wasn't changed in the last iteration.
351355
return failure(changed);

0 commit comments

Comments
 (0)