[Mlir-commits] [mlir] [mlir][Transforms][NFC] Dialect Conversion: Earlier `isIgnored` check (PR #148360)
Matthias Springer
llvmlistbot at llvm.org
Sat Jul 12 04:29:04 PDT 2025
https://github.com/matthias-springer updated https://github.com/llvm/llvm-project/pull/148360
>From bab09c2d4c67edf361e6d7094bdaccf668f9494c 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 | 32 ++++++++++++-------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index d118fe422f2f2..9f71129d39d09 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2075,20 +2075,37 @@ OperationLegalizer::legalize(Operation *op,
auto &logger = rewriter.getImpl().logger;
#endif
+
+ // Check to see if the operation is ignored and doesn't need to be converted.
+ bool isIgnored = rewriter.getImpl().isOpIgnored(op);
+
LLVM_DEBUG({
logger.getOStream() << "\n";
logger.startLine() << logLineComment;
- logger.startLine() << "Legalizing operation : '" << op->getName() << "'("
- << op << ") {\n";
+ logger.startLine() << "Legalizing operation : ";
+ // Do not print the operation name if the operation is ignored. Ignored ops
+ // may have been erased and should not be accessed. The pointer can be
+ // printed safely.
+ if (!isIgnored)
+ logger.getOStream() << "'" << op->getName() << "' ";
+ logger.getOStream() << "(" << op << ") {\n";
logger.indent();
// If the operation has no regions, just print it here.
- if (op->getNumRegions() == 0) {
+ if (!isIgnored && op->getNumRegions() == 0) {
op->print(logger.startLine(), OpPrintingFlags().printGenericOpForm());
logger.getOStream() << "\n\n";
}
});
+ 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 +2129,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