[mlir][Transforms] GreedyPatternRewriteDriver debugging: Detect faulty patterns
authorMatthias Springer <me@m-sp.org>
Wed, 24 May 2023 14:14:47 +0000 (16:14 +0200)
committerMatthias Springer <me@m-sp.org>
Wed, 24 May 2023 14:22:08 +0000 (16:22 +0200)
commite6d90a0d5e202166a9846f1845196086aa02f35e
treefa5258afd4bc36356f0f92f21cccef304e01ed51
parent0ea5eb143c7a63105b4479c455642b4c4ef3278c
[mlir][Transforms] GreedyPatternRewriteDriver debugging: Detect faulty patterns

Compute operation finger prints to detect incorrect API usage in RewritePatterns. Does not work for dialect conversion patterns.

Detect patterns that:
* Returned `failure` but changed the IR.
* Returned `success` but did not change the IR.
* Inserted/removed/modified ops, bypassing the rewriter. Not all cases are detected.

These new checks are quite expensive, so they are only enabled with `-DMLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=ON`. Failures manifest as fatal errors (`llvm::report_fatal_error`) or crashes (accessing deallocated memory). To get better debugging information, run `mlir-opt -debug` (to see which pattern is broken) with ASAN (to see where memory was deallocated).

Differential Revision: https://reviews.llvm.org/D144552
mlir/CMakeLists.txt
mlir/include/mlir/Config/mlir-config.h.cmake [new file with mode: 0644]
mlir/include/mlir/IR/PatternMatch.h
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp