[mlir] Add option to limit number of pattern rewrites in CanonicalizerPass
authorMatthias Springer <springerm@google.com>
Fri, 23 Dec 2022 12:01:00 +0000 (13:01 +0100)
committerMatthias Springer <springerm@google.com>
Fri, 23 Dec 2022 12:08:53 +0000 (13:08 +0100)
commit391cb541223bb0d41620eb5e25c107563dc3e12c
tree06ac5d45388aac79bd681a616bd6e6c263242662
parent4861a58769e882fc9fef2ec55429a639deb0aa42
[mlir] Add option to limit number of pattern rewrites in CanonicalizerPass

The greedy pattern rewriter consists of two nested loops. `config.maxIterations` (which configurable on the CanonicalizerPass) controls the maximum number of iterations of the outer loop.

```
/// This specifies the maximum number of times the rewriter will iterate
/// between applying patterns and simplifying regions. Use `kNoLimit` to
/// disable this iteration limit.
int64_t maxIterations = 10;
```

This change adds `config.maxNumRewrites` which controls the maximum number of pattern rewrites within an iteration. (It effectively control the maximum number of iterations of the inner loop.)

This flag is meant for debugging and useful in cases where one or multiple faulty patterns can be applied indefinitely, resulting in an infinite loop.

Differential Revision: https://reviews.llvm.org/D140525
mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h
mlir/include/mlir/Transforms/Passes.td
mlir/lib/Transforms/Canonicalizer.cpp
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
mlir/test/Pass/run-reproducer.mlir