[Mlir-commits] [mlir] [mlir][EmitC] Do not convert illegal types in EmitC (PR #104571)
Longsheng Mou
llvmlistbot at llvm.org
Tue Aug 20 00:18:35 PDT 2024
https://github.com/CoTinker updated https://github.com/llvm/llvm-project/pull/104571
>From 3d2c326bbbe77514f3c2cd21337f87dfaf4df2dd Mon Sep 17 00:00:00 2001
From: Longsheng Mou <moulongsheng at huawei.com>
Date: Fri, 16 Aug 2024 17:19:15 +0800
Subject: [PATCH] [mlir][EmitC] Do not convert illegal types in EmitC
This patch adds check for unsupported types in emitc, which
fixes a crash.
---
.../MemRefToEmitC/MemRefToEmitCPass.cpp | 6 +++---
.../MemRefToEmitC/memref-to-emitc-failed.mlir | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
index 4e5d1912d15729..11bfde890bce87 100644
--- a/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
+++ b/mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
@@ -33,9 +33,9 @@ struct ConvertMemRefToEmitCPass
// Fallback for other types.
converter.addConversion([](Type type) -> std::optional<Type> {
- if (isa<MemRefType>(type))
- return {};
- return type;
+ if (emitc::isSupportedEmitCType(type))
+ return type;
+ return {};
});
populateMemRefToEmitCTypeConversion(converter);
diff --git a/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir b/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir
index 89dafa7529ed53..836d8aedefc1f0 100644
--- a/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir
+++ b/mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-failed.mlir
@@ -43,3 +43,19 @@ func.func @zero_rank() {
// expected-error at +1 {{failed to legalize operation 'memref.global'}}
memref.global "nested" constant @nested_global : memref<3x7xf32>
+
+// -----
+
+func.func @unsupported_type_f16() {
+ // expected-error at +1 {{failed to legalize operation 'memref.alloca'}}
+ %0 = memref.alloca() : memref<4xf16>
+ return
+}
+
+// -----
+
+func.func @unsupported_type_i4() {
+ // expected-error at +1 {{failed to legalize operation 'memref.alloca'}}
+ %0 = memref.alloca() : memref<4xi4>
+ return
+}
More information about the Mlir-commits
mailing list