[Mlir-commits] [mlir] [mlir][Transforms] GreedyPatternRewriteDriver: verify IR after pattern application (PR #74270)
Matthias Springer
llvmlistbot at llvm.org
Sun Dec 3 18:30:22 PST 2023
https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/74270
This commit adds an additional "expensive check" that verifies the IR after every pattern application. (Only if `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` is set.)
There are currently 89 tests that are failing with this check. Many of them are in the `vector` and `SparseTensor` dialects, most of which are probably failing due to same reason. The actual number of patterns that produce invalid IR is probably in the order of 10.
This commit does not fix any patterns, this is done in separate commits.
>From 29a8a3f81633bd357422390826ee2eef8a596e26 Mon Sep 17 00:00:00 2001
From: Matthias Springer <springerm at google.com>
Date: Mon, 4 Dec 2023 11:28:43 +0900
Subject: [PATCH] [mlir][Transforms] GreedyPatternRewriteDriver: verify IR
after pattern application
This commit adds an additional "expensive check" that verifies the IR after every pattern application. (Only if `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS` is set.)
There are currently 89 tests that are failing with this check. Many of them are in the `vector` and `SparseTensor` dialects, most of which are probably failing due to same reason. The actual number of patterns that produce invalid IR is probably in the order of 10.
This commit does not fix any patterns, this is done in separate commits.
---
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index 8e2bfe557c555..93a259a82cd2b 100644
--- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -15,6 +15,7 @@
#include "mlir/Config/mlir-config.h"
#include "mlir/IR/Action.h"
#include "mlir/IR/Matchers.h"
+#include "mlir/IR/Verifier.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Rewrite/PatternApplicator.h"
#include "mlir/Transforms/FoldUtils.h"
@@ -468,11 +469,19 @@ bool GreedyPatternRewriteDriver::processWorklist() {
/*topLevel=*/config.scope ? config.scope->getParentOp() : op);
auto clearFingerprints =
llvm::make_scope_exit([&]() { debugFingerPrints.clear(); });
+ Operation *rootOp =
+ op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
+ assert(rootOp && "expected non-null root op");
#endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
LogicalResult matchResult =
matcher.matchAndRewrite(op, *this, canApply, onFailure, onSuccess);
+#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
+ if (failed(verify(rootOp)))
+ llvm::report_fatal_error("IR failed to verify after pattern application");
+#endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
+
if (succeeded(matchResult)) {
LLVM_DEBUG(logResultWithLine("success", "pattern matched"));
#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
More information about the Mlir-commits
mailing list