Skip to content

Commit 1bb48c4

Browse files
committed
[mlir][emitc] Add literal op testing (NFC)
- Literal ops are emitted as unused variables under declare-variables-at-top - Translator fails to emit literals used as emitc.call arguments
1 parent e6bd68c commit 1bb48c4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

mlir/test/Target/Cpp/literal.mlir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
2+
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
3+
4+
func.func @emitc_literal(%arg0: f32) {
5+
%p0 = emitc.literal "M_PI" : f32
6+
%1 = "emitc.add" (%arg0, %p0) : (f32, f32) -> f32
7+
return
8+
}
9+
// CPP-DEFAULT: void emitc_literal(float [[V0:[^ ]*]]) {
10+
// CPP-DEFAULT: float [[V2:[^ ]*]] = [[V0:[^ ]*]] + M_PI
11+
12+
// CPP-DECLTOP: void emitc_literal(float [[V0:[^ ]*]]) {
13+
// CPP-DECLTOP: float M_PI;
14+
// CPP-DECLTOP: float [[V1:[^ ]*]];
15+
// CPP-DECLTOP: [[V1]] = [[V0:[^ ]*]] + M_PI
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
2+
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
3+
// XFAIL: *
4+
5+
func.func @emitc_call_operand() {
6+
%p0 = emitc.literal "M_PI" : f32
7+
%1 = emitc.call "foo"(%p0) : (f32) -> f32
8+
return
9+
}
10+
// CPP-DEFAULT: void emitc_call_operand() {
11+
// CPP-DEFAULT-NEXT: float v1 = foo(M_PI);
12+
13+
// CPP-DECLTOP: void emitc_call_operand() {
14+
// CPP-DECLTOP-NEXT: float M_PI;
15+
// CPP-DECLTOP-NEXT: float v1;
16+
// CPP-DECLTOP-NEXT: v1 = foo(M_PI);

0 commit comments

Comments
 (0)