Skip to content

[mlir][emitc] Clean up EmitC tests #152327

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

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlir/test/Dialect/EmitC/attrs.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: mlir-opt -verify-diagnostics %s | FileCheck %s
// RUN: mlir-opt %s | FileCheck %s
// check parser
// RUN: mlir-opt -verify-diagnostics %s | mlir-opt -verify-diagnostics | FileCheck %s
// RUN: mlir-opt %s | mlir-opt | FileCheck %s

// CHECK-LABEL: func @opaque_attrs() {
func.func @opaque_attrs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt %s --form-expressions --verify-diagnostics --split-input-file | FileCheck %s
// RUN: mlir-opt %s -form-expressions | FileCheck %s

// CHECK-LABEL: func.func @single_expression(
// CHECK-SAME: %[[VAL_0:.*]]: i32, %[[VAL_1:.*]]: i32, %[[VAL_2:.*]]: i32, %[[VAL_3:.*]]: i32) -> i1 {
Expand Down Expand Up @@ -83,7 +83,6 @@ func.func @expression_with_dereference(%arg0: i32, %arg1: i32, %arg2: !emitc.ptr
return %c : i1
}


// CHECK-LABEL: func.func @expression_with_address_taken(
// CHECK-SAME: %[[VAL_0:.*]]: i32, %[[VAL_1:.*]]: i32, %[[VAL_2:.*]]: !emitc.ptr<i32>) -> i1 {
// CHECK: %[[VAL_3:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>
Expand Down Expand Up @@ -121,9 +120,8 @@ func.func @no_nested_expression(%arg0: i32, %arg1: i32) -> i1 {
return %a : i1
}


// CHECK-LABEL: func.func @single_result_requirement
// CHECK-NOT: emitc.expression
// CHECK-NOT: emitc.expression

func.func @single_result_requirement() -> (i32, i32) {
%0:2 = emitc.call_opaque "foo" () : () -> (i32, i32)
Expand Down Expand Up @@ -152,7 +150,6 @@ func.func @single_result_requirement() -> (i32, i32) {
// CHECK: return %[[VAL_9]] : i1
// CHECK: }


func.func @expression_with_load(%arg0: i32, %arg1: !emitc.ptr<i32>) -> i1 {
%c0 = "emitc.constant"() {value = 0 : i64} : () -> i64
%0 = "emitc.variable"() <{value = #emitc.opaque<"42">}> : () -> !emitc.lvalue<i32>
Expand Down
12 changes: 12 additions & 0 deletions mlir/test/Dialect/EmitC/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,15 @@ func.func @switch() {

return
}

emitc.class final @finalClass {
emitc.field @fieldName0 : !emitc.array<1xf32>
emitc.field @fieldName1 : !emitc.array<1xf32>
emitc.func @execute() {
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
%1 = get_field @fieldName0 : !emitc.array<1xf32>
%2 = get_field @fieldName1 : !emitc.array<1xf32>
%3 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
return
}
}
6 changes: 3 additions & 3 deletions mlir/test/Dialect/EmitC/types.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: mlir-opt -verify-diagnostics -allow-unregistered-dialect %s | FileCheck %s
// check parser
// RUN: mlir-opt -verify-diagnostics -allow-unregistered-dialect %s | mlir-opt -verify-diagnostics --allow-unregistered-dialect | FileCheck %s
// RUN: mlir-opt %s -allow-unregistered-dialect | FileCheck %s
// Check parser
// RUN: mlir-opt %s -allow-unregistered-dialect | mlir-opt -allow-unregistered-dialect | FileCheck %s

// CHECK-LABEL: func @array_types(
func.func @array_types(
Expand Down
57 changes: 57 additions & 0 deletions mlir/test/Dialect/EmitC/wrap-func-in-class.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// RUN: mlir-opt %s -wrap-emitc-func-in-class -split-input-file | FileCheck %s

emitc.func @foo(%arg0 : !emitc.array<1xf32>) {
emitc.call_opaque "bar" (%arg0) : (!emitc.array<1xf32>) -> ()
emitc.return
}

// CHECK: module {
// CHECK: emitc.class @fooClass {
// CHECK: emitc.field @fieldName0 : !emitc.array<1xf32>
// CHECK: emitc.func @execute() {
// CHECK: %0 = get_field @fieldName0 : !emitc.array<1xf32>
// CHECK: call_opaque "bar"(%0) : (!emitc.array<1xf32>) -> ()
// CHECK: return
// CHECK: }
// CHECK: }
// CHECK: }

// -----

module attributes { } {
emitc.func @model(%arg0: !emitc.array<1xf32> {emitc.name_hint = "another_feature"},
%arg1: !emitc.array<1xf32> {emitc.name_hint = "some_feature"},
%arg2: !emitc.array<1xf32> {emitc.name_hint = "output_0"}) attributes { } {
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
%1 = subscript %arg1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
%2 = load %1 : <f32>
%3 = subscript %arg0[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
%4 = load %3 : <f32>
%5 = add %2, %4 : (f32, f32) -> f32
%6 = subscript %arg2[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
assign %5 : f32 to %6 : <f32>
return
}
}

// CHECK: module {
// CHECK: emitc.class @modelClass {
// CHECK: emitc.field @fieldName0 : !emitc.array<1xf32> {emitc.name_hint = "another_feature"}
// CHECK: emitc.field @fieldName1 : !emitc.array<1xf32> {emitc.name_hint = "some_feature"}
// CHECK: emitc.field @fieldName2 : !emitc.array<1xf32> {emitc.name_hint = "output_0"}
// CHECK: emitc.func @execute() {
// CHECK: get_field @fieldName0 : !emitc.array<1xf32>
// CHECK: get_field @fieldName1 : !emitc.array<1xf32>
// CHECK: get_field @fieldName2 : !emitc.array<1xf32>
// CHECK: "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
// CHECK: subscript {{.*}}[{{.*}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
// CHECK: load {{.*}} : <f32>
// CHECK: subscript {{.*}}[{{.*}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
// CHECK: load {{.*}} : <f32>
// CHECK: add {{.*}}, {{.*}} : (f32, f32) -> f32
// CHECK: subscript {{.*}}[{{.*}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
// CHECK: assign {{.*}} : f32 to {{.*}} : <f32>
// CHECK: return
// CHECK: }
// CHECK: }
// CHECK: }
40 changes: 0 additions & 40 deletions mlir/test/Dialect/EmitC/wrap_emitc_func_in_class.mlir

This file was deleted.

17 changes: 0 additions & 17 deletions mlir/test/Dialect/EmitC/wrap_emitc_func_in_class_noAttr.mlir

This file was deleted.

78 changes: 78 additions & 0 deletions mlir/test/Target/Cpp/class.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s

emitc.class @modelClass {
emitc.field @fieldName0 : !emitc.array<1xf32>
emitc.field @fieldName1 : !emitc.array<1xf32>
emitc.func @execute() {
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
%1 = get_field @fieldName0 : !emitc.array<1xf32>
%2 = get_field @fieldName1 : !emitc.array<1xf32>
%3 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
return
}
}

// CHECK-LABEL: class modelClass {
// CHECK-NEXT: public:
// CHECK-NEXT: float fieldName0[1];
// CHECK-NEXT: float fieldName1[1];
// CHECK-NEXT: void execute() {
// CHECK-NEXT: size_t v1 = 0;
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK-NEXT: };

emitc.class final @finalClass {
emitc.field @fieldName0 : !emitc.array<1xf32>
emitc.field @fieldName1 : !emitc.array<1xf32>
emitc.func @execute() {
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
%1 = get_field @fieldName0 : !emitc.array<1xf32>
%2 = get_field @fieldName1 : !emitc.array<1xf32>
%3 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
return
}
}

// CHECK-LABEL: class finalClass final {
// CHECK-NEXT: public:
// CHECK-NEXT: float fieldName0[1];
// CHECK-NEXT: float fieldName1[1];
// CHECK-NEXT: void execute() {
// CHECK-NEXT: size_t v1 = 0;
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK-NEXT: };

emitc.class @mainClass {
emitc.field @fieldName0 : !emitc.array<2xf32> = dense<0.0> {attrs = {emitc.name_hint = "another_feature"}}
emitc.func @get_fieldName0() {
%0 = emitc.get_field @fieldName0 : !emitc.array<2xf32>
return
}
}

// CHECK-LABEL: class mainClass {
// CHECK-NEXT: public:
// CHECK-NEXT: float fieldName0[2] = {0.0e+00f, 0.0e+00f};
// CHECK-NEXT: void get_fieldName0() {
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK-NEXT: };

emitc.class @reflectionClass {
emitc.field @reflectionMap : !emitc.opaque<"const std::map<std::string, std::string>"> = #emitc.opaque<"{ { \22another_feature\22, \22fieldName0\22 } }">
emitc.func @get_reflectionMap() {
%0 = emitc.get_field @reflectionMap : !emitc.opaque<"const std::map<std::string, std::string>">
return
}
}

// CHECK-LABEL: class reflectionClass {
// CHECK-NEXT: public:
// CHECK-NEXT: const std::map<std::string, std::string> reflectionMap = { { "another_feature", "fieldName0" } };
// CHECK-NEXT: void get_reflectionMap() {
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK-NEXT: };

78 changes: 0 additions & 78 deletions mlir/test/mlir-translate/emitc_classops.mlir

This file was deleted.