[mlir][emitc] Do not convert illegal types to emitc (#156222)

This PR adds fallbacks for other types instead of converting unsupported
types to emitc.
This commit is contained in:
Longsheng Mou 2026-03-03 09:06:23 +08:00 committed by GitHub
parent 2407564cbf
commit 8decfb8a90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View File

@ -42,7 +42,12 @@ void ConvertArithToEmitC::runOnOperation() {
RewritePatternSet patterns(&getContext());
TypeConverter typeConverter;
typeConverter.addConversion([](Type type) { return type; });
// Fallback for other types.
typeConverter.addConversion([](Type type) -> std::optional<Type> {
if (!emitc::isSupportedEmitCType(type))
return {};
return type;
});
populateArithToEmitCPatterns(typeConverter, patterns);

View File

@ -41,7 +41,12 @@ void ConvertFuncToEmitC::runOnOperation() {
RewritePatternSet patterns(&getContext());
TypeConverter typeConverter;
typeConverter.addConversion([](Type type) { return type; });
// Fallback for other types.
typeConverter.addConversion([](Type type) -> std::optional<Type> {
if (!emitc::isSupportedEmitCType(type))
return {};
return type;
});
populateFuncToEmitCPatterns(typeConverter, patterns);

View File

@ -13,3 +13,11 @@ func.func @vector(%arg0: vector<4xi32>, %arg1: vector<4xi32>) {
%0 = arith.addi %arg0, %arg1 : vector<4xi32>
return
}
// -----
func.func @unsuppoted_emitc_type(%arg0: i4, %arg1: i4) {
// expected-error@+1 {{failed to legalize operation 'arith.addi'}}
%0 = arith.addi %arg0, %arg1 : i4
return
}

View File

@ -0,0 +1,6 @@
// RUN: mlir-opt -convert-func-to-emitc %s -split-input-file -verify-diagnostics
// expected-error@+1 {{failed to legalize operation 'func.func'}}
func.func @unsuppoted_emitc_type(%arg0: i4) -> i4 {
return %arg0 : i4
}