[Mlir-commits] [mlir] [mlir][Transforms][NFC] Dialect Conversion: Earlier `isIgnored` check (PR #148360)

Matthias Springer llvmlistbot at llvm.org
Sat Jul 12 04:22:23 PDT 2025


https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/148360

When legalizing an operation, the conversion driver skips "ignored" ops. Ops are ignored if they are inside of a recursively legal operation or if they were erased.

This commit moves the "is ignored" check a bit earlier: it is now checked before checking if the op is recursively legal. This is in preparation of the One-Shot Dialect Conversion refactoring: erased ops should not be accessed, not even for checking recursive legality.

This commit is NFC: When an op is erased, it is added to the set of ignored ops and we don't want to process it, regardless of legality. Nested ops are also added to the set of ignored ops when erasing an enclosing op.


>From ba36ea51d5bc81ba453448231ea2f384f75a29b2 Mon Sep 17 00:00:00 2001
From: Matthias Springer <me at m-sp.org>
Date: Sat, 12 Jul 2025 11:16:17 +0000
Subject: [PATCH] [mlir][Transforms][NFC] Dialect Conversion: Earlier
 `isIgnored` check

---
 .../Transforms/Utils/DialectConversion.cpp    | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index d118fe422f2f2..645e6b8727968 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2089,6 +2089,16 @@ OperationLegalizer::legalize(Operation *op,
     }
   });
 
+  // Check to see if the operation is ignored and doesn't need to be converted.
+  bool isIgnored = rewriter.getImpl().isOpIgnored(op);
+  if (isIgnored) {
+    LLVM_DEBUG({
+      logSuccess(logger, "operation marked 'ignored' during conversion");
+      logger.startLine() << logLineComment;
+    });
+    return success();
+  }
+
   // Check if this operation is legal on the target.
   if (auto legalityInfo = target.isLegal(op)) {
     LLVM_DEBUG({
@@ -2112,15 +2122,6 @@ OperationLegalizer::legalize(Operation *op,
     return success();
   }
 
-  // Check to see if the operation is ignored and doesn't need to be converted.
-  if (rewriter.getImpl().isOpIgnored(op)) {
-    LLVM_DEBUG({
-      logSuccess(logger, "operation marked 'ignored' during conversion");
-      logger.startLine() << logLineComment;
-    });
-    return success();
-  }
-
   // If the operation isn't legal, try to fold it in-place.
   // TODO: Should we always try to do this, even if the op is
   // already legal?



More information about the Mlir-commits mailing list