forked from OSchip/llvm-project
[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
This commit is contained in:
parent
10b93a5dec
commit
519663beba
|
@ -33,8 +33,11 @@ public:
|
||||||
bool enableRegionSimplification = true;
|
bool enableRegionSimplification = true;
|
||||||
|
|
||||||
/// This specifies the maximum number of times the rewriter will iterate
|
/// This specifies the maximum number of times the rewriter will iterate
|
||||||
/// between applying patterns and simplifying regions.
|
/// between applying patterns and simplifying regions. Use `kNoIterationLimit`
|
||||||
unsigned maxIterations = 10;
|
/// to disable this iteration limit.
|
||||||
|
int64_t maxIterations = 10;
|
||||||
|
|
||||||
|
static constexpr int64_t kNoIterationLimit = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -378,7 +378,7 @@ def Canonicalizer : Pass<"canonicalize"> {
|
||||||
Option<"enableRegionSimplification", "region-simplify", "bool",
|
Option<"enableRegionSimplification", "region-simplify", "bool",
|
||||||
/*default=*/"true",
|
/*default=*/"true",
|
||||||
"Seed the worklist in general top-down order">,
|
"Seed the worklist in general top-down order">,
|
||||||
Option<"maxIterations", "max-iterations", "unsigned",
|
Option<"maxIterations", "max-iterations", "int64_t",
|
||||||
/*default=*/"10",
|
/*default=*/"10",
|
||||||
"Seed the worklist in general top-down order">
|
"Seed the worklist in general top-down order">
|
||||||
] # RewritePassUtils.options;
|
] # RewritePassUtils.options;
|
||||||
|
|
|
@ -222,7 +222,9 @@ bool GreedyPatternRewriteDriver::simplify(MutableArrayRef<Region> regions) {
|
||||||
// is kept up to date.
|
// is kept up to date.
|
||||||
if (config.enableRegionSimplification)
|
if (config.enableRegionSimplification)
|
||||||
changed |= succeeded(simplifyRegions(*this, regions));
|
changed |= succeeded(simplifyRegions(*this, regions));
|
||||||
} while (changed && ++iteration < config.maxIterations);
|
} while (changed &&
|
||||||
|
(++iteration < config.maxIterations ||
|
||||||
|
config.maxIterations == GreedyRewriteConfig::kNoIterationLimit));
|
||||||
|
|
||||||
// Whether the rewrite converges, i.e. wasn't changed in the last iteration.
|
// Whether the rewrite converges, i.e. wasn't changed in the last iteration.
|
||||||
return !changed;
|
return !changed;
|
||||||
|
@ -345,7 +347,9 @@ LogicalResult OpPatternRewriteDriver::simplifyLocally(Operation *op,
|
||||||
changed |= succeeded(matcher.matchAndRewrite(op, *this));
|
changed |= succeeded(matcher.matchAndRewrite(op, *this));
|
||||||
if ((erased = opErasedViaPatternRewrites))
|
if ((erased = opErasedViaPatternRewrites))
|
||||||
return success();
|
return success();
|
||||||
} while (changed && ++iterations < maxIterations);
|
} while (changed &&
|
||||||
|
(++iterations < maxIterations ||
|
||||||
|
maxIterations == GreedyRewriteConfig::kNoIterationLimit));
|
||||||
|
|
||||||
// Whether the rewrite converges, i.e. wasn't changed in the last iteration.
|
// Whether the rewrite converges, i.e. wasn't changed in the last iteration.
|
||||||
return failure(changed);
|
return failure(changed);
|
||||||
|
|
Loading…
Reference in New Issue