[Mlir-commits] [mlir] 67db348 - [mlir][Transforms][NFC] Dialect Conversion: Earlier `isIgnored` check (#148360)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jul 12 07:46:46 PDT 2025
Author: Matthias Springer
Date: 2025-07-12T16:46:42+02:00
New Revision: 67db34863cefb4ddb71babbe22416c89cf743564
URL: https://github.com/llvm/llvm-project/commit/67db34863cefb4ddb71babbe22416c89cf743564
DIFF: https://github.com/llvm/llvm-project/commit/67db34863cefb4ddb71babbe22416c89cf743564.diff
LOG: [mlir][Transforms][NFC] Dialect Conversion: Earlier `isIgnored` check (#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.
Added:
Modified:
mlir/lib/Transforms/Utils/DialectConversion.cpp
Removed:
################################################################################
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