Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions mlir/lib/Transforms/Utils/DialectConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,44 @@ void ConversionPatternRewriterImpl::replaceOp(
Operation *op, SmallVector<SmallVector<Value>> &&newValues) {
assert(newValues.size() == op->getNumResults() &&
"incorrect number of replacement values");
LLVM_DEBUG({
logger.startLine() << "** Replace : '" << op->getName() << "'(" << op
<< ")\n";
if (currentTypeConverter) {
// If the user-provided replacement types are different from the
// legalized types, as per the current type converter, print a note.
// In most cases, the replacement types are expected to match the types
// produced by the type converter, so this could indicate a bug in the
// user code.
for (auto [result, repls] :
llvm::zip_equal(op->getResults(), newValues)) {
Type resultType = result.getType();
auto logProlog = [&, repls = repls]() {
logger.startLine() << " Note: Replacing op result of type "
<< resultType << " with value(s) of type (";
llvm::interleaveComma(repls, logger.getOStream(), [&](Value v) {
logger.getOStream() << v.getType();
});
logger.getOStream() << ")";
};
SmallVector<Type> convertedTypes;
if (failed(currentTypeConverter->convertTypes(resultType,
convertedTypes))) {
logProlog();
logger.getOStream() << ", but the type converter failed to legalize "
"the original type.\n";
continue;
}
if (TypeRange(convertedTypes) != TypeRange(ValueRange(repls))) {
logProlog();
logger.getOStream() << ", but the legalized type(s) is/are (";
llvm::interleaveComma(convertedTypes, logger.getOStream(),
[&](Type t) { logger.getOStream() << t; });
logger.getOStream() << ")\n";
}
}
}
});

if (!config.allowPatternRollback) {
// Pattern rollback is not allowed: materialize all IR changes immediately.
Expand Down Expand Up @@ -2072,10 +2110,6 @@ void ConversionPatternRewriter::replaceOp(Operation *op, Operation *newOp) {
void ConversionPatternRewriter::replaceOp(Operation *op, ValueRange newValues) {
assert(op->getNumResults() == newValues.size() &&
"incorrect # of replacement values");
LLVM_DEBUG({
impl->logger.startLine()
<< "** Replace : '" << op->getName() << "'(" << op << ")\n";
});

// If the current insertion point is before the erased operation, we adjust
// the insertion point to be after the operation.
Expand All @@ -2093,10 +2127,6 @@ void ConversionPatternRewriter::replaceOpWithMultiple(
Operation *op, SmallVector<SmallVector<Value>> &&newValues) {
assert(op->getNumResults() == newValues.size() &&
"incorrect # of replacement values");
LLVM_DEBUG({
impl->logger.startLine()
<< "** Replace : '" << op->getName() << "'(" << op << ")\n";
});

// If the current insertion point is before the erased operation, we adjust
// the insertion point to be after the operation.
Expand Down
Loading