[Mlir-commits] [mlir] [mlir] Add missing materialization function diag for dialect convertion (PR #207689)
lonely eagle
llvmlistbot at llvm.org
Mon Aug 3 08:06:25 PDT 2026
https://github.com/linuxlonelyeagle updated https://github.com/llvm/llvm-project/pull/207689
>From 956528e989859ec3ae08e033dba9e595abec51ab Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 6 Jul 2026 09:36:26 +0000
Subject: [PATCH 1/4] add miss diag for dialect convertion.
---
.../Transforms/Utils/DialectConversion.cpp | 11 ++++++++++
.../Arith/emulate-wide-int-unsupported.mlir | 4 ++--
.../test-legalize-type-conversion.mlir | 20 +++++++++----------
3 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index c76e3808d3b37..a27fcc888f1eb 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -3383,6 +3383,17 @@ legalizeUnresolvedMaterialization(RewriterBase &rewriter,
rewriter.replaceOp(op, newMaterialization);
return success();
}
+ StringRef direction =
+ info.getMaterializationKind() == MaterializationKind::Target ? "target"
+ : "source";
+ InFlightDiagnostic diag = op.emitError()
+ << "miss " << direction
+ << " materialization function from ("
+ << inputOperands.getTypes() << ") to ("
+ << op.getResultTypes() << ")";
+ diag.attachNote(op->getUsers().begin()->getLoc())
+ << "require this materialization is here";
+ return failure();
}
InFlightDiagnostic diag = op->emitError()
diff --git a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
index 44f09b920ed4f..6be6f4f04e5d5 100644
--- a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
+++ b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
@@ -45,9 +45,9 @@ func.func @unsupported_argument_type(%arg0: vector<4xi128>) -> vector<4xi64> {
// Ensure this case not crash
func.func @unsupported_vector(%arg0: vector<2xi1>) {
- // expected-error at +1 {{failed to legalize unresolved materialization from ('vector<2x2xi32>') to ('vector<2xi64>') that remained live after conversion}}
+ // expected-error at +1 {{miss source materialization function from ('vector<2x2xi32>') to ('vector<2xi64>')}}
%cst_0 = arith.constant dense<0> : vector<2xi64>
- // expected-note at +1 {{see existing live user here}}
+ // expected-note at +1 {{require this materialization is here}}
%0 = vector.mask %arg0 { vector.multi_reduction <xor>, %cst_0, %cst_0 [] : vector<2xi64> to vector<2xi64> } : vector<2xi1> -> vector<2xi64>
return
}
diff --git a/mlir/test/Transforms/test-legalize-type-conversion.mlir b/mlir/test/Transforms/test-legalize-type-conversion.mlir
index 1453045c3bfbc..5dcfb34ceb39d 100644
--- a/mlir/test/Transforms/test-legalize-type-conversion.mlir
+++ b/mlir/test/Transforms/test-legalize-type-conversion.mlir
@@ -2,9 +2,9 @@
func.func @test_invalid_arg_materialization(
- // expected-error at below {{failed to legalize unresolved materialization from () to ('i16') that remained live after conversion}}
+ // expected-error at below {{miss source materialization function from () to ('i16')}}
%arg0: i16) {
- // expected-note at below{{see existing live user here}}
+ // expected-note at below{{require this materialization is here}}
"foo.return"(%arg0) : (i16) -> ()
}
@@ -21,18 +21,18 @@ func.func @test_valid_arg_materialization(%arg0: i64) {
// -----
func.func @test_invalid_result_materialization() {
- // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+ // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
%result = "test.type_producer"() : () -> f16
- // expected-note at below{{see existing live user here}}
+ // expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
}
// -----
func.func @test_invalid_result_materialization() {
- // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+ // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
%result = "test.type_producer"() : () -> f16
- // expected-note at below{{see existing live user here}}
+ // expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
}
@@ -50,9 +50,9 @@ func.func @test_transitive_use_materialization() {
// -----
func.func @test_transitive_use_invalid_materialization() {
- // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+ // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
%result = "test.another_type_producer"() : () -> f16
- // expected-note at below{{see existing live user here}}
+ // expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
}
@@ -194,9 +194,9 @@ gpu.module @cuda_events {
// hashes and could differ with LLVM_ENABLE_REVERSE_ITERATION.
func.func @test_deterministic_materialization_order() {
- // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f16') that remained live after conversion}}
+ // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
%a = "test.type_producer"() : () -> f16
%b = "test.type_producer"() : () -> f16
- // expected-note at below {{see existing live user here}}
+ // expected-note at below {{require this materialization is here}}
"foo.return"(%a, %b) : (f16, f16) -> ()
}
>From f9efa5bcbb5090199a0e8c9e1bad3117e21b9fde Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 6 Jul 2026 12:37:49 +0000
Subject: [PATCH 2/4] fix python test.
---
mlir/test/python/rewrite.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/python/rewrite.py b/mlir/test/python/rewrite.py
index 35d88833e69e0..8b667810b9953 100644
--- a/mlir/test/python/rewrite.py
+++ b/mlir/test/python/rewrite.py
@@ -316,7 +316,7 @@ def convert_muli(op, adaptor, type_converter, rewriter):
apply_partial_conversion(module, target, frozen)
except MLIRError as e:
# CHECK: caught exception: partial conversion failed
- # CHECK: failed to legalize unresolved materialization
+ # CHECK: miss target materialization function
print("caught exception:", e)
t1 = converter.convert_type(IntegerType.get_signless(64))
>From 0bc60c301ff85d99b6ccfd8dd274b5e134947248 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 6 Jul 2026 14:01:10 +0000
Subject: [PATCH 3/4] update code.
---
mlir/lib/Transforms/Utils/DialectConversion.cpp | 14 +++++++-------
.../Arith/emulate-wide-int-unsupported.mlir | 2 +-
.../Transforms/test-legalize-type-conversion.mlir | 12 ++++++------
mlir/test/python/rewrite.py | 2 +-
4 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index a27fcc888f1eb..856b27c29d913 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -3387,7 +3387,7 @@ legalizeUnresolvedMaterialization(RewriterBase &rewriter,
info.getMaterializationKind() == MaterializationKind::Target ? "target"
: "source";
InFlightDiagnostic diag = op.emitError()
- << "miss " << direction
+ << "mismatch " << direction
<< " materialization function from ("
<< inputOperands.getTypes() << ") to ("
<< op.getResultTypes() << ")";
@@ -3396,12 +3396,12 @@ legalizeUnresolvedMaterialization(RewriterBase &rewriter,
return failure();
}
- InFlightDiagnostic diag = op->emitError()
- << "failed to legalize unresolved materialization "
- "from ("
- << inputOperands.getTypes() << ") to ("
- << op.getResultTypes()
- << ") that remained live after conversion";
+ InFlightDiagnostic diag =
+ op->emitError()
+ << "failed to legalize unresolved materialization "
+ "from ("
+ << inputOperands.getTypes() << ") to (" << op.getResultTypes()
+ << ") that remained live after conversion (no type converter specified)";
diag.attachNote(op->getUsers().begin()->getLoc())
<< "see existing live user here: " << *op->getUsers().begin();
return failure();
diff --git a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
index 6be6f4f04e5d5..ad8393ec7de89 100644
--- a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
+++ b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
@@ -45,7 +45,7 @@ func.func @unsupported_argument_type(%arg0: vector<4xi128>) -> vector<4xi64> {
// Ensure this case not crash
func.func @unsupported_vector(%arg0: vector<2xi1>) {
- // expected-error at +1 {{miss source materialization function from ('vector<2x2xi32>') to ('vector<2xi64>')}}
+ // expected-error at +1 {{mismatch source materialization function from ('vector<2x2xi32>') to ('vector<2xi64>')}}
%cst_0 = arith.constant dense<0> : vector<2xi64>
// expected-note at +1 {{require this materialization is here}}
%0 = vector.mask %arg0 { vector.multi_reduction <xor>, %cst_0, %cst_0 [] : vector<2xi64> to vector<2xi64> } : vector<2xi1> -> vector<2xi64>
diff --git a/mlir/test/Transforms/test-legalize-type-conversion.mlir b/mlir/test/Transforms/test-legalize-type-conversion.mlir
index 5dcfb34ceb39d..c8fbbbfa7fdd9 100644
--- a/mlir/test/Transforms/test-legalize-type-conversion.mlir
+++ b/mlir/test/Transforms/test-legalize-type-conversion.mlir
@@ -2,7 +2,7 @@
func.func @test_invalid_arg_materialization(
- // expected-error at below {{miss source materialization function from () to ('i16')}}
+ // expected-error at below {{mismatch source materialization function from () to ('i16')}}
%arg0: i16) {
// expected-note at below{{require this materialization is here}}
"foo.return"(%arg0) : (i16) -> ()
@@ -21,7 +21,7 @@ func.func @test_valid_arg_materialization(%arg0: i64) {
// -----
func.func @test_invalid_result_materialization() {
- // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
%result = "test.type_producer"() : () -> f16
// expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
@@ -30,7 +30,7 @@ func.func @test_invalid_result_materialization() {
// -----
func.func @test_invalid_result_materialization() {
- // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
%result = "test.type_producer"() : () -> f16
// expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
@@ -50,7 +50,7 @@ func.func @test_transitive_use_materialization() {
// -----
func.func @test_transitive_use_invalid_materialization() {
- // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
%result = "test.another_type_producer"() : () -> f16
// expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
@@ -102,7 +102,7 @@ func.func @test_block_argument_not_converted() {
// Make sure argument type changes aren't implicitly forwarded.
func.func @test_signature_conversion_no_converter() {
"test.signature_conversion_no_converter"() ({
- // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f32') that remained live after conversion}}
+ // expected-error at below {{failed to legalize unresolved materialization from ('f64') to ('f32') that remained live after conversion (no type converter specified)}}
^bb0(%arg0: f32):
// expected-note at below{{see existing live user here}}
"test.type_consumer"(%arg0) : (f32) -> ()
@@ -194,7 +194,7 @@ gpu.module @cuda_events {
// hashes and could differ with LLVM_ENABLE_REVERSE_ITERATION.
func.func @test_deterministic_materialization_order() {
- // expected-error at below {{miss source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
%a = "test.type_producer"() : () -> f16
%b = "test.type_producer"() : () -> f16
// expected-note at below {{require this materialization is here}}
diff --git a/mlir/test/python/rewrite.py b/mlir/test/python/rewrite.py
index 8b667810b9953..d0419ae4aad6e 100644
--- a/mlir/test/python/rewrite.py
+++ b/mlir/test/python/rewrite.py
@@ -316,7 +316,7 @@ def convert_muli(op, adaptor, type_converter, rewriter):
apply_partial_conversion(module, target, frozen)
except MLIRError as e:
# CHECK: caught exception: partial conversion failed
- # CHECK: miss target materialization function
+ # CHECK: mismatch target materialization function
print("caught exception:", e)
t1 = converter.convert_type(IntegerType.get_signless(64))
>From af3d72a285bf0aa030a403edd823b46a0b0e7295 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 3 Aug 2026 14:58:08 +0000
Subject: [PATCH 4/4] update code.
---
mlir/lib/Transforms/Utils/DialectConversion.cpp | 11 ++++++-----
.../Dialect/Arith/emulate-wide-int-unsupported.mlir | 2 +-
.../Transforms/test-legalize-type-conversion.mlir | 10 +++++-----
mlir/test/python/rewrite.py | 2 +-
4 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 856b27c29d913..5bea1150e1580 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -3386,11 +3386,12 @@ legalizeUnresolvedMaterialization(RewriterBase &rewriter,
StringRef direction =
info.getMaterializationKind() == MaterializationKind::Target ? "target"
: "source";
- InFlightDiagnostic diag = op.emitError()
- << "mismatch " << direction
- << " materialization function from ("
- << inputOperands.getTypes() << ") to ("
- << op.getResultTypes() << ")";
+ InFlightDiagnostic diag =
+ op.emitError()
+ << "failed to legalize unresolved " << direction
+ << " materialization from (" << inputOperands.getTypes() << ") to ("
+ << op.getResultTypes()
+ << ") that remained live after conversion (no matching callback)";
diag.attachNote(op->getUsers().begin()->getLoc())
<< "require this materialization is here";
return failure();
diff --git a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
index ad8393ec7de89..ad0590d749eef 100644
--- a/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
+++ b/mlir/test/Dialect/Arith/emulate-wide-int-unsupported.mlir
@@ -45,7 +45,7 @@ func.func @unsupported_argument_type(%arg0: vector<4xi128>) -> vector<4xi64> {
// Ensure this case not crash
func.func @unsupported_vector(%arg0: vector<2xi1>) {
- // expected-error at +1 {{mismatch source materialization function from ('vector<2x2xi32>') to ('vector<2xi64>')}}
+ // expected-error at +1 {{failed to legalize unresolved source materialization from ('vector<2x2xi32>') to ('vector<2xi64>') that remained live after conversion (no matching callback)}}
%cst_0 = arith.constant dense<0> : vector<2xi64>
// expected-note at +1 {{require this materialization is here}}
%0 = vector.mask %arg0 { vector.multi_reduction <xor>, %cst_0, %cst_0 [] : vector<2xi64> to vector<2xi64> } : vector<2xi1> -> vector<2xi64>
diff --git a/mlir/test/Transforms/test-legalize-type-conversion.mlir b/mlir/test/Transforms/test-legalize-type-conversion.mlir
index c8fbbbfa7fdd9..66579b4842217 100644
--- a/mlir/test/Transforms/test-legalize-type-conversion.mlir
+++ b/mlir/test/Transforms/test-legalize-type-conversion.mlir
@@ -2,7 +2,7 @@
func.func @test_invalid_arg_materialization(
- // expected-error at below {{mismatch source materialization function from () to ('i16')}}
+ // expected-error at below {{failed to legalize unresolved source materialization from () to ('i16') that remained live after conversion (no matching callback)}}
%arg0: i16) {
// expected-note at below{{require this materialization is here}}
"foo.return"(%arg0) : (i16) -> ()
@@ -21,7 +21,7 @@ func.func @test_valid_arg_materialization(%arg0: i64) {
// -----
func.func @test_invalid_result_materialization() {
- // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{failed to legalize unresolved source materialization from ('f64') to ('f16') that remained live after conversion (no matching callback)}}
%result = "test.type_producer"() : () -> f16
// expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
@@ -30,7 +30,7 @@ func.func @test_invalid_result_materialization() {
// -----
func.func @test_invalid_result_materialization() {
- // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{failed to legalize unresolved source materialization from ('f64') to ('f16') that remained live after conversion (no matching callback)}}
%result = "test.type_producer"() : () -> f16
// expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
@@ -50,7 +50,7 @@ func.func @test_transitive_use_materialization() {
// -----
func.func @test_transitive_use_invalid_materialization() {
- // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{failed to legalize unresolved source materialization from ('f64') to ('f16') that remained live after conversion (no matching callback)}}
%result = "test.another_type_producer"() : () -> f16
// expected-note at below{{require this materialization is here}}
"foo.return"(%result) : (f16) -> ()
@@ -194,7 +194,7 @@ gpu.module @cuda_events {
// hashes and could differ with LLVM_ENABLE_REVERSE_ITERATION.
func.func @test_deterministic_materialization_order() {
- // expected-error at below {{mismatch source materialization function from ('f64') to ('f16')}}
+ // expected-error at below {{failed to legalize unresolved source materialization from ('f64') to ('f16') that remained live after conversion (no matching callback)}}
%a = "test.type_producer"() : () -> f16
%b = "test.type_producer"() : () -> f16
// expected-note at below {{require this materialization is here}}
diff --git a/mlir/test/python/rewrite.py b/mlir/test/python/rewrite.py
index d0419ae4aad6e..1cd3e70d3dfce 100644
--- a/mlir/test/python/rewrite.py
+++ b/mlir/test/python/rewrite.py
@@ -316,7 +316,7 @@ def convert_muli(op, adaptor, type_converter, rewriter):
apply_partial_conversion(module, target, frozen)
except MLIRError as e:
# CHECK: caught exception: partial conversion failed
- # CHECK: mismatch target materialization function
+ # CHECK: failed to legalize unresolved target materialization
print("caught exception:", e)
t1 = converter.convert_type(IntegerType.get_signless(64))
More information about the Mlir-commits
mailing list