[Mlir-commits] [mlir] 9db9f6d - [mlir][emitc] Refactor the e2e test for TOSA -> EmitC lowering (#194686)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue May 5 05:18:42 PDT 2026


Author: Andrzej WarzyƄski
Date: 2026-05-05T13:18:37+01:00
New Revision: 9db9f6d9c985f38075f2e0a3f55646d13fe0953c

URL: https://github.com/llvm/llvm-project/commit/9db9f6d9c985f38075f2e0a3f55646d13fe0953c
DIFF: https://github.com/llvm/llvm-project/commit/9db9f6d9c985f38075f2e0a3f55646d13fe0953c.diff

LOG: [mlir][emitc] Refactor the e2e test for TOSA -> EmitC lowering (#194686)

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.

Added: 
    mlir/test/Integration/Dialect/EmitC/lit.local.cfg
    mlir/test/Integration/Dialect/EmitC/td.mlir
    mlir/test/Integration/Dialect/EmitC/tosa.mlir

Modified: 
    

Removed: 
    mlir/test/Dialect/EmitC/tosa/lit.local.cfg
    mlir/test/Dialect/EmitC/tosa/ops.mlir
    mlir/test/Dialect/EmitC/tosa/td.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..b23164c9c4b9e
--- /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 -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}
+
+/// 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>
+}


        


More information about the Mlir-commits mailing list