-
Notifications
You must be signed in to change notification settings - Fork 15k
[mlir][emitc] Do not convert illegal types to emitc #156222
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
base: main
Are you sure you want to change the base?
Conversation
This PR adds fallbacks for other types instead of converting unsupported types to emtic.
@llvm/pr-subscribers-mlir Author: Longsheng Mou (CoTinker) ChangesThis PR adds fallbacks for other types instead of converting unsupported types to emtic. Full diff: https://github.com/llvm/llvm-project/pull/156222.diff 4 Files Affected:
diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp
index 45a088ed144f1..5ab1627ec40f3 100644
--- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp
+++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp
@@ -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);
diff --git a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp
index 5b59e7675d7c6..b82a7266dc95f 100644
--- a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp
+++ b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp
@@ -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);
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
index 30abd81f3d447..fba4483d316f4 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
@@ -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
+}
diff --git a/mlir/test/Conversion/FuncToEmitC/func-to-emitc-failed.mlir b/mlir/test/Conversion/FuncToEmitC/func-to-emitc-failed.mlir
new file mode 100644
index 0000000000000..73b3adeedaecd
--- /dev/null
+++ b/mlir/test/Conversion/FuncToEmitC/func-to-emitc-failed.mlir
@@ -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
+}
|
@llvm/pr-subscribers-mlir-emitc Author: Longsheng Mou (CoTinker) ChangesThis PR adds fallbacks for other types instead of converting unsupported types to emtic. Full diff: https://github.com/llvm/llvm-project/pull/156222.diff 4 Files Affected:
diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp
index 45a088ed144f1..5ab1627ec40f3 100644
--- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp
+++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitCPass.cpp
@@ -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);
diff --git a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp
index 5b59e7675d7c6..b82a7266dc95f 100644
--- a/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp
+++ b/mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp
@@ -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);
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
index 30abd81f3d447..fba4483d316f4 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-failed.mlir
@@ -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
+}
diff --git a/mlir/test/Conversion/FuncToEmitC/func-to-emitc-failed.mlir b/mlir/test/Conversion/FuncToEmitC/func-to-emitc-failed.mlir
new file mode 100644
index 0000000000000..73b3adeedaecd
--- /dev/null
+++ b/mlir/test/Conversion/FuncToEmitC/func-to-emitc-failed.mlir
@@ -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
+}
|
Ping~ |
This PR adds fallbacks for other types instead of converting unsupported types to emtic.