[Mlir-commits] [mlir] [emitC]Option to mlir-translate class instead of function (PR #141158)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jun 6 16:24:38 PDT 2025


Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Jaddyen <ajaden at google.com>,Jaddyen
 <ajaden at google.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/141158 at github.com>


================

----------------
Jaddyen wrote:

What you get out at this time:

```cpp
"builtin.module"() ({
  "emitc.class"() <{sym_name = "MyModelClass"}> ({
    "emitc.field"() <{initial_value = {another_feature}, sym_name = "another_feature", type = !emitc.array<1xf32>}> : () -> ()
    "emitc.field"() <{initial_value = {some_feature}, sym_name = "some_feature", type = !emitc.array<1xf32>}> : () -> ()
    "emitc.field"() <{initial_value = {output_0}, sym_name = "output_0", type = !emitc.array<1xf32>}> : () -> ()
    "emitc.func"() <{function_type = (!emitc.array<1xf32>, !emitc.array<1xf32>, !emitc.array<1xf32>) -> (), sym_name = "execute"}> ({
      %7 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
      %8 = "emitc.subscript"(%arg1, %7) : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
      %9 = "emitc.load"(%8) : (!emitc.lvalue<f32>) -> f32
      %10 = "emitc.subscript"(%arg0, %7) : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
      %11 = "emitc.load"(%10) : (!emitc.lvalue<f32>) -> f32
      %12 = "emitc.add"(%9, %11) : (f32, f32) -> f32
      %13 = "emitc.subscript"(%arg2, %7) : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
      "emitc.assign"(%13, %12) : (!emitc.lvalue<f32>, f32) -> ()
      "emitc.return"() : () -> ()
    }) : () -> ()
  }) : () -> ()
  "emitc.func"() <{arg_attrs = [{tf_saved_model.index_path = ["another_feature"]}, {tf_saved_model.index_path = ["some_feature"]}, {tf_saved_model.index_path = ["output_0"]}], function_type = (!emitc.array<1xf32>, !emitc.array<1xf32>, !emitc.array<1xf32>) -> (), sym_name = "main"}> ({
  ^bb0(%arg0: !emitc.array<1xf32>, %arg1: !emitc.array<1xf32>, %arg2: !emitc.array<1xf32>):
    %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
    %1 = "emitc.subscript"(%arg1, %0) : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
    %2 = "emitc.load"(%1) : (!emitc.lvalue<f32>) -> f32
    %3 = "emitc.subscript"(%arg0, %0) : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
    %4 = "emitc.load"(%3) : (!emitc.lvalue<f32>) -> f32
    %5 = "emitc.add"(%2, %4) : (f32, f32) -> f32
    %6 = "emitc.subscript"(%arg2, %0) : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
    "emitc.assign"(%6, %5) : (!emitc.lvalue<f32>, f32) -> ()
    "emitc.return"() : () -> ()
  }) {tf.entry_function = {inputs = "serving_default_another_feature:0,serving_default_some_feature:0", outputs = "PartitionedCall:0"}, tf_saved_model.exported_names = ["serving_default"]} : () -> ()
}) {tf_saved_model.semantics, tfl.description = "MLIR Converted.", tfl.schema_version = 3 : i32} : () -> ()
```

We need to have a way to erase the previous `funcOp` by ensuring all uses to it are lost.
I've replacing its uses with `newFuncOp` then erasing `funcOp` but that didnt work. The check for whether it is empty returns true but erasing it raises an error. Hence we still have it here.

https://github.com/llvm/llvm-project/pull/141158


More information about the Mlir-commits mailing list