-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir] Dialect conversion: Print note when replacement types do not match legalized types #161802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir] Dialect conversion: Print note when replacement types do not match legalized types #161802
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Matthias Springer (matthias-springer) ChangesWhen running with Example output:
Full diff: https://github.com/llvm/llvm-project/pull/161802.diff 1 Files Affected:
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index bf0136b39e03c..65bc4df9571b8 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -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.
@@ -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.
@@ -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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice thanks!
…atch legalized types
85e8e94
to
34137fb
Compare
When running with
-debug
, print a note when the replacement types (during aConversionPatternRewriter::replaceOp
) do not match the legalized types of the current type converter. That's not an API violation, but it could indicate a bug in user code.Example output: