Skip to content

Commit 67db348

Browse files
[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.
1 parent 96d57de commit 67db348

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,20 +2075,37 @@ OperationLegalizer::legalize(Operation *op,
20752075

20762076
auto &logger = rewriter.getImpl().logger;
20772077
#endif
2078+
2079+
// Check to see if the operation is ignored and doesn't need to be converted.
2080+
bool isIgnored = rewriter.getImpl().isOpIgnored(op);
2081+
20782082
LLVM_DEBUG({
20792083
logger.getOStream() << "\n";
20802084
logger.startLine() << logLineComment;
2081-
logger.startLine() << "Legalizing operation : '" << op->getName() << "'("
2082-
<< op << ") {\n";
2085+
logger.startLine() << "Legalizing operation : ";
2086+
// Do not print the operation name if the operation is ignored. Ignored ops
2087+
// may have been erased and should not be accessed. The pointer can be
2088+
// printed safely.
2089+
if (!isIgnored)
2090+
logger.getOStream() << "'" << op->getName() << "' ";
2091+
logger.getOStream() << "(" << op << ") {\n";
20832092
logger.indent();
20842093

20852094
// If the operation has no regions, just print it here.
2086-
if (op->getNumRegions() == 0) {
2095+
if (!isIgnored && op->getNumRegions() == 0) {
20872096
op->print(logger.startLine(), OpPrintingFlags().printGenericOpForm());
20882097
logger.getOStream() << "\n\n";
20892098
}
20902099
});
20912100

2101+
if (isIgnored) {
2102+
LLVM_DEBUG({
2103+
logSuccess(logger, "operation marked 'ignored' during conversion");
2104+
logger.startLine() << logLineComment;
2105+
});
2106+
return success();
2107+
}
2108+
20922109
// Check if this operation is legal on the target.
20932110
if (auto legalityInfo = target.isLegal(op)) {
20942111
LLVM_DEBUG({
@@ -2112,15 +2129,6 @@ OperationLegalizer::legalize(Operation *op,
21122129
return success();
21132130
}
21142131

2115-
// Check to see if the operation is ignored and doesn't need to be converted.
2116-
if (rewriter.getImpl().isOpIgnored(op)) {
2117-
LLVM_DEBUG({
2118-
logSuccess(logger, "operation marked 'ignored' during conversion");
2119-
logger.startLine() << logLineComment;
2120-
});
2121-
return success();
2122-
}
2123-
21242132
// If the operation isn't legal, try to fold it in-place.
21252133
// TODO: Should we always try to do this, even if the op is
21262134
// already legal?

0 commit comments

Comments
 (0)