forked from OSchip/llvm-project
Add an optional argument for pattern rewriter max iteration count (NFC)
Some rewriters take more iterations to converge, add a parameter to overwrite the built-in maximum iteration count. Fix PR48073. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D91553
This commit is contained in:
parent
499bce3aba
commit
fbceee2d63
|
@ -24,20 +24,38 @@ namespace mlir {
|
|||
|
||||
/// Rewrite the regions of the specified operation, which must be isolated from
|
||||
/// above, by repeatedly applying the highest benefit patterns in a greedy
|
||||
/// work-list driven manner. Return success if no more patterns can be matched
|
||||
/// in the result operation regions.
|
||||
/// Note: This does not apply patterns to the top-level operation itself. Note:
|
||||
/// work-list driven manner.
|
||||
/// This variant may stop after a predefined number of iterations, see the
|
||||
/// alternative below to provide a specific number of iterations before stopping
|
||||
/// in absence of convergence.
|
||||
/// Return success if the iterative process converged and no more patterns can
|
||||
/// be matched in the result operation regions.
|
||||
/// Note: This does not apply patterns to the top-level operation itself.
|
||||
/// These methods also perform folding and simple dead-code elimination
|
||||
/// before attempting to match any of the provided patterns.
|
||||
///
|
||||
LogicalResult
|
||||
applyPatternsAndFoldGreedily(Operation *op,
|
||||
const FrozenRewritePatternList &patterns);
|
||||
|
||||
/// Rewrite the regions of the specified operation, with a user-provided limit
|
||||
/// on iterations to attempt before reaching convergence.
|
||||
LogicalResult
|
||||
applyPatternsAndFoldGreedily(Operation *op,
|
||||
const FrozenRewritePatternList &patterns,
|
||||
unsigned maxIterations);
|
||||
|
||||
/// Rewrite the given regions, which must be isolated from above.
|
||||
LogicalResult
|
||||
applyPatternsAndFoldGreedily(MutableArrayRef<Region> regions,
|
||||
const FrozenRewritePatternList &patterns);
|
||||
|
||||
/// Rewrite the given regions, with a user-provided limit on iterations to
|
||||
/// attempt before reaching convergence.
|
||||
LogicalResult
|
||||
applyPatternsAndFoldGreedily(MutableArrayRef<Region> regions,
|
||||
const FrozenRewritePatternList &patterns,
|
||||
unsigned maxIterations);
|
||||
|
||||
/// Applies the specified patterns on `op` alone while also trying to fold it,
|
||||
/// by selecting the highest benefits patterns in a greedy manner. Returns
|
||||
/// success if no more patterns can be matched. `erased` is set to true if `op`
|
||||
|
|
|
@ -220,12 +220,26 @@ bool GreedyPatternRewriteDriver::simplify(MutableArrayRef<Region> regions,
|
|||
LogicalResult
|
||||
mlir::applyPatternsAndFoldGreedily(Operation *op,
|
||||
const FrozenRewritePatternList &patterns) {
|
||||
return applyPatternsAndFoldGreedily(op->getRegions(), patterns);
|
||||
return applyPatternsAndFoldGreedily(op, patterns, maxPatternMatchIterations);
|
||||
}
|
||||
LogicalResult
|
||||
mlir::applyPatternsAndFoldGreedily(Operation *op,
|
||||
const FrozenRewritePatternList &patterns,
|
||||
unsigned maxIterations) {
|
||||
return applyPatternsAndFoldGreedily(op->getRegions(), patterns,
|
||||
maxIterations);
|
||||
}
|
||||
/// Rewrite the given regions, which must be isolated from above.
|
||||
LogicalResult
|
||||
mlir::applyPatternsAndFoldGreedily(MutableArrayRef<Region> regions,
|
||||
const FrozenRewritePatternList &patterns) {
|
||||
return applyPatternsAndFoldGreedily(regions, patterns,
|
||||
maxPatternMatchIterations);
|
||||
}
|
||||
LogicalResult
|
||||
mlir::applyPatternsAndFoldGreedily(MutableArrayRef<Region> regions,
|
||||
const FrozenRewritePatternList &patterns,
|
||||
unsigned maxIterations) {
|
||||
if (regions.empty())
|
||||
return success();
|
||||
|
||||
|
@ -241,10 +255,10 @@ mlir::applyPatternsAndFoldGreedily(MutableArrayRef<Region> regions,
|
|||
|
||||
// Start the pattern driver.
|
||||
GreedyPatternRewriteDriver driver(regions[0].getContext(), patterns);
|
||||
bool converged = driver.simplify(regions, maxPatternMatchIterations);
|
||||
bool converged = driver.simplify(regions, maxIterations);
|
||||
LLVM_DEBUG(if (!converged) {
|
||||
llvm::dbgs() << "The pattern rewrite doesn't converge after scanning "
|
||||
<< maxPatternMatchIterations << " times";
|
||||
<< maxIterations << " times";
|
||||
});
|
||||
return success(converged);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue