[Mlir-commits] [mlir] [mlir][emitc] Refactor the e2e test for TOSA -> EmitC lowering (PR #194686)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Wed Apr 29 01:05:19 PDT 2026
https://github.com/banach-space updated https://github.com/llvm/llvm-project/pull/194686
>From 1283cb593d861b70ddd19ea498aa3378dc1ff783 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Tue, 28 Apr 2026 17:08:07 +0000
Subject: [PATCH 1/2] [mlir][emitc] Refactor the e2e test for TOSA -> EmitC
lowering
Update the TOSA -> EmitC test, mlir/test/Dialect/EmitC/tosa/ops.mlir,
to also compile the generated source with a C++ compiler. This adds an
`mlir-translate` step, making the overall flow:
mlir-opt tosa.mlir | mlir-translate | c++ -Wall -Werror -c
Although the test still does not execute the generated code, compiling it
with a host compiler increases coverage and makes the test closer to an
integration test. For this reason, move it to:
mlir/test/Integration/Dialect/EmitC/
The source generated by the translator uses `size_t`, which requires the
`stddef.h` header. This is currently provided explicitly in the compile step
with `-include stddef.h`; a follow-up should consider emitting the required
include from the translator instead.
---
mlir/test/Dialect/EmitC/tosa/ops.mlir | 43 -------------------
.../Dialect/EmitC}/lit.local.cfg | 0
.../Dialect/EmitC}/td.mlir | 0
mlir/test/Integration/Dialect/EmitC/tosa.mlir | 37 ++++++++++++++++
4 files changed, 37 insertions(+), 43 deletions(-)
delete mode 100644 mlir/test/Dialect/EmitC/tosa/ops.mlir
rename mlir/test/{Dialect/EmitC/tosa => Integration/Dialect/EmitC}/lit.local.cfg (100%)
rename mlir/test/{Dialect/EmitC/tosa => Integration/Dialect/EmitC}/td.mlir (100%)
create mode 100644 mlir/test/Integration/Dialect/EmitC/tosa.mlir
diff --git a/mlir/test/Dialect/EmitC/tosa/ops.mlir b/mlir/test/Dialect/EmitC/tosa/ops.mlir
deleted file mode 100644
index 9f08a95438dfe..0000000000000
--- a/mlir/test/Dialect/EmitC/tosa/ops.mlir
+++ /dev/null
@@ -1,43 +0,0 @@
-// DEFINE: %{pipeline} = "builtin.module(\
-// DEFINE: func.func(\
-// DEFINE: tosa-to-linalg\
-// DEFINE: ),\
-// DEFINE: one-shot-bufferize{\
-// DEFINE: bufferize-function-boundaries\
-// DEFINE: function-boundary-type-conversion=identity-layout-map\
-// DEFINE: },\
-// DEFINE: buffer-results-to-out-params{\
-// DEFINE: hoist-static-allocs=true\
-// DEFINE: },\
-// DEFINE: func.func(\
-// DEFINE: convert-linalg-to-loops\
-// DEFINE: ),\
-// DEFINE: canonicalize,\
-// DEFINE: convert-to-emitc\
-// DEFINE: )"
-
-// RUN: mlir-opt --pass-pipeline=%{pipeline} %s | FileCheck %s
-
-// RUN: mlir-opt -split-input-file \
-// RUN: -transform-preload-library='transform-library-paths=%p/td.mlir' \
-// RUN: -transform-interpreter %s -test-transform-dialect-erase-schedule | mlir-opt -convert-to-emitc | FileCheck %s
-
-// CHECK: emitc.func private @add(%[[ARG0:.*]]: !emitc.array<2xf32>, %[[ARG1:.*]]: !emitc.array<2xf32>, %[[RES:.*]]: !emitc.array<2xf32>)
-// CHECK-DAG: %[[C0:.*]] = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
-// CHECK-DAG: %[[C1:.*]] = "emitc.constant"() <{value = 1 : index}> : () -> !emitc.size_t
-// CHECK-DAG: %[[C2:.*]] = "emitc.constant"() <{value = 2 : index}> : () -> !emitc.size_t
-// CHECK-NEXT: for %[[INDEX:.*]] = %[[C0]] to %[[C2]] step %[[C1]] : !emitc.size_t {
-// CHECK-NEXT: %[[V0_LVALUE:.*]] = subscript %[[ARG0]][%[[INDEX]]] : (!emitc.array<2xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
-// CHECK-NEXT: %[[V0:.*]] = load %[[V0_LVALUE]] : <f32>
-// CHECK-NEXT: %[[V1_LVALUE:.*]] = subscript %[[ARG1]][%[[INDEX]]] : (!emitc.array<2xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
-// CHECK-NEXT: %[[V1:.*]] = load %[[V1_LVALUE]] : <f32>
-// CHECK-NEXT: %[[VADD:.*]] = add %[[V0]], %[[V1]] : (f32, f32) -> f32
-// CHECK-NEXT: %[[RES_LVALUE:.*]] = subscript %[[RES]][%[[INDEX]]] : (!emitc.array<2xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
-// CHECK-NEXT: assign %[[VADD]] : f32 to %[[RES_LVALUE]] : <f32>
-// CHECK-NEXT: }
-// CHECK-NEXT: return
-// CHECK-NEXT: }
-func.func private @add(%arg0: tensor<2xf32>, %arg1: tensor<2xf32>) -> tensor<2xf32> {
- %0 = tosa.add %arg0, %arg1 : (tensor<2xf32>, tensor<2xf32>) -> tensor<2xf32>
- return %0 : tensor<2xf32>
-}
diff --git a/mlir/test/Dialect/EmitC/tosa/lit.local.cfg b/mlir/test/Integration/Dialect/EmitC/lit.local.cfg
similarity index 100%
rename from mlir/test/Dialect/EmitC/tosa/lit.local.cfg
rename to mlir/test/Integration/Dialect/EmitC/lit.local.cfg
diff --git a/mlir/test/Dialect/EmitC/tosa/td.mlir b/mlir/test/Integration/Dialect/EmitC/td.mlir
similarity index 100%
rename from mlir/test/Dialect/EmitC/tosa/td.mlir
rename to mlir/test/Integration/Dialect/EmitC/td.mlir
diff --git a/mlir/test/Integration/Dialect/EmitC/tosa.mlir b/mlir/test/Integration/Dialect/EmitC/tosa.mlir
new file mode 100644
index 0000000000000..fa20843f6d1f2
--- /dev/null
+++ b/mlir/test/Integration/Dialect/EmitC/tosa.mlir
@@ -0,0 +1,37 @@
+// DEFINE: %{pipeline} = "builtin.module(\
+// DEFINE: func.func(\
+// DEFINE: tosa-to-linalg\
+// DEFINE: ),\
+// DEFINE: one-shot-bufferize{\
+// DEFINE: bufferize-function-boundaries\
+// DEFINE: function-boundary-type-conversion=identity-layout-map\
+// DEFINE: },\
+// DEFINE: buffer-results-to-out-params{\
+// DEFINE: hoist-static-allocs=true\
+// DEFINE: },\
+// DEFINE: func.func(\
+// DEFINE: convert-linalg-to-loops\
+// DEFINE: ),\
+// DEFINE: canonicalize,\
+// DEFINE: convert-to-emitc\
+// DEFINE: )"
+
+// DEFINE: %{lower_to_emitc} = mlir-opt --pass-pipeline=%{pipeline} %s -o %t
+// DEFINE: %{translate} = mlir-translate -mlir-to-cpp %t -o %t.c
+// DEFINE: %{compile} = %host_cc -include stddef.h -c -Wpedantic -Wall -Werror -Wno-unused %t.c
+
+/// Lower via the pipeline defined above
+// RUN: rm -f %t && %{lower_to_emitc} && FileCheck %s --input-file=%t && %{translate} && %{compile}
+
+/// Lower via Transform Dialect
+// REDEFINE: %{lower_to_emitc} = mlir-opt %s \
+// REDEFINE: -transform-preload-library='transform-library-paths=%p/td.mlir' \
+// REDEFINE: -transform-interpreter -test-transform-dialect-erase-schedule | mlir-opt -convert-to-emitc -o %t
+// RUN: rm -f %t && %{lower_to_emitc} && FileCheck %s --input-file=%t && %{translate} && %{compile}
+
+// CHECK-LABEL: @add
+// CHECK: add {{.*}} : (f32, f32) -> f32
+func.func private @add(%arg0: tensor<2xf32>, %arg1: tensor<2xf32>) -> tensor<2xf32> {
+ %0 = tosa.add %arg0, %arg1 : (tensor<2xf32>, tensor<2xf32>) -> tensor<2xf32>
+ return %0 : tensor<2xf32>
+}
>From b51597a65512e80a9b413b21163582a7d0f047c9 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Wed, 29 Apr 2026 08:05:04 +0000
Subject: [PATCH 2/2] Replace -c with -fsyntax-only
---
mlir/test/Integration/Dialect/EmitC/tosa.mlir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/Integration/Dialect/EmitC/tosa.mlir b/mlir/test/Integration/Dialect/EmitC/tosa.mlir
index fa20843f6d1f2..b23164c9c4b9e 100644
--- a/mlir/test/Integration/Dialect/EmitC/tosa.mlir
+++ b/mlir/test/Integration/Dialect/EmitC/tosa.mlir
@@ -18,7 +18,7 @@
// DEFINE: %{lower_to_emitc} = mlir-opt --pass-pipeline=%{pipeline} %s -o %t
// DEFINE: %{translate} = mlir-translate -mlir-to-cpp %t -o %t.c
-// DEFINE: %{compile} = %host_cc -include stddef.h -c -Wpedantic -Wall -Werror -Wno-unused %t.c
+// DEFINE: %{compile} = %host_cc -include stddef.h -fsyntax-only -Wpedantic -Wall -Werror -Wno-unused %t.c
/// Lower via the pipeline defined above
// RUN: rm -f %t && %{lower_to_emitc} && FileCheck %s --input-file=%t && %{translate} && %{compile}
More information about the Mlir-commits
mailing list