[Mlir-commits] [mlir] [mlir] Fix debug output for passes that modify top-level operation. (PR #80022)

Robert Konicar llvmlistbot at llvm.org
Wed Jan 31 02:09:56 PST 2024


https://github.com/Jezurko updated https://github.com/llvm/llvm-project/pull/80022

>From 3ecf2c4fa377d9d4edad1b8e219766b66002fa1a Mon Sep 17 00:00:00 2001
From: Robert Konicar <xkonicar at fi.muni.cz>
Date: Tue, 30 Jan 2024 16:12:03 +0100
Subject: [PATCH 1/2] [mlir] Fix debug output for passes that modify top-level
 operation.

Make it so that when the top-level (root) operation itself is being
modified, it is also used as the root for debug output in
PatternApplicator.
---
 mlir/lib/Rewrite/PatternApplicator.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Rewrite/PatternApplicator.cpp b/mlir/lib/Rewrite/PatternApplicator.cpp
index 0064eb84aba84..686aef2e68e11 100644
--- a/mlir/lib/Rewrite/PatternApplicator.cpp
+++ b/mlir/lib/Rewrite/PatternApplicator.cpp
@@ -40,7 +40,9 @@ static void logImpossibleToMatch(const Pattern &pattern) {
 
 /// Log IR after pattern application.
 static Operation *getDumpRootOp(Operation *op) {
-  return op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
+  return op->hasTrait<mlir::OpTrait::IsIsolatedFromAbove>()
+             ? op
+             : op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
 }
 static void logSucessfulPatternApplication(Operation *op) {
   llvm::dbgs() << "// *** IR Dump After Pattern Application ***\n";

>From 56f280ce6d1e950b2f8d416ad8fb5e867c73ec99 Mon Sep 17 00:00:00 2001
From: Robert Konicar <xkonicar at fi.muni.cz>
Date: Wed, 31 Jan 2024 10:33:15 +0100
Subject: [PATCH 2/2] Make it so that the old behaviour is preserved more
 generally

---
 mlir/lib/Rewrite/PatternApplicator.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Rewrite/PatternApplicator.cpp b/mlir/lib/Rewrite/PatternApplicator.cpp
index 686aef2e68e11..ea43f8a147d47 100644
--- a/mlir/lib/Rewrite/PatternApplicator.cpp
+++ b/mlir/lib/Rewrite/PatternApplicator.cpp
@@ -40,9 +40,11 @@ static void logImpossibleToMatch(const Pattern &pattern) {
 
 /// Log IR after pattern application.
 static Operation *getDumpRootOp(Operation *op) {
-  return op->hasTrait<mlir::OpTrait::IsIsolatedFromAbove>()
-             ? op
-             : op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
+  Operation *isolatedParent =
+      op->getParentWithTrait<mlir::OpTrait::IsIsolatedFromAbove>();
+  if (isolatedParent)
+    return isolatedParent;
+  return op;
 }
 static void logSucessfulPatternApplication(Operation *op) {
   llvm::dbgs() << "// *** IR Dump After Pattern Application ***\n";



More information about the Mlir-commits mailing list