Skip to content

Commit df8e92b

Browse files
committed
[mlir][emitc] Add test case for the index type
1 parent e7d1c50 commit df8e92b

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

mlir/test/Target/Cpp/switch.mlir

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,75 @@
11
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
22
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
33

4+
// CPP-DEFAULT-LABEL: void emitc_switch_index() {
5+
// CPP-DEFAULT: size_t v1 = 1;
6+
// CPP-DEFAULT: switch (v1) {
7+
// CPP-DEFAULT: case (2): {
8+
// CPP-DEFAULT: int32_t v2 = func_b();
9+
// CPP-DEFAULT: break;
10+
// CPP-DEFAULT: }
11+
// CPP-DEFAULT: case (5): {
12+
// CPP-DEFAULT: int32_t v3 = func_a();
13+
// CPP-DEFAULT: break;
14+
// CPP-DEFAULT: }
15+
// CPP-DEFAULT: default: {
16+
// CPP-DEFAULT: float v4 = 4.200000000e+01f;
17+
// CPP-DEFAULT: float v5 = 4.200000000e+01f;
18+
// CPP-DEFAULT: func2(v4);
19+
// CPP-DEFAULT: func3(v5, v4);
20+
// CPP-DEFAULT: break;
21+
// CPP-DEFAULT: }
22+
// CPP-DEFAULT: return;
23+
// CPP-DEFAULT: }
24+
25+
// CPP-DECLTOP-LABEL: void emitc_switch_index() {
26+
// CPP-DECLTOP: size_t v1;
27+
// CPP-DECLTOP: float v2;
28+
// CPP-DECLTOP: float v3;
29+
// CPP-DECLTOP: int32_t v4;
30+
// CPP-DECLTOP: int32_t v5;
31+
// CPP-DECLTOP: v1 = 1;
32+
// CPP-DECLTOP: switch (v1) {
33+
// CPP-DECLTOP: case (2): {
34+
// CPP-DECLTOP: v4 = func_b();
35+
// CPP-DECLTOP: break;
36+
// CPP-DECLTOP: }
37+
// CPP-DECLTOP: case (5): {
38+
// CPP-DECLTOP: v5 = func_a();
39+
// CPP-DECLTOP: break;
40+
// CPP-DECLTOP: }
41+
// CPP-DECLTOP: default: {
42+
// CPP-DECLTOP: v2 = 4.200000000e+01f;
43+
// CPP-DECLTOP: v3 = 4.200000000e+01f;
44+
// CPP-DECLTOP: func2(v2);
45+
// CPP-DECLTOP: func3(v3, v2);
46+
// CPP-DECLTOP: break;
47+
// CPP-DECLTOP: }
48+
// CPP-DECLTOP: return;
49+
// CPP-DECLTOP: }
50+
func.func @emitc_switch_index() {
51+
%0 = "emitc.variable"(){value = 1 : index} : () -> index
52+
53+
emitc.switch %0 : index
54+
case 2: {
55+
%1 = emitc.call_opaque "func_b" () : () -> i32
56+
emitc.yield
57+
}
58+
case 5: {
59+
%2 = emitc.call_opaque "func_a" () : () -> i32
60+
emitc.yield
61+
}
62+
default: {
63+
%3 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
64+
%4 = "emitc.variable"(){value = 42.0 : f32} : () -> f32
65+
66+
emitc.call_opaque "func2" (%3) : (f32) -> ()
67+
emitc.call_opaque "func3" (%3, %4) { args = [1 : index, 0 : index] } : (f32, f32) -> ()
68+
emitc.yield
69+
}
70+
return
71+
}
72+
473
// CPP-DEFAULT-LABEL: void emitc_switch_opaque() {
574
// CPP-DEFAULT: size_t v1 = 1;
675
// CPP-DEFAULT: switch (v1) {

0 commit comments

Comments
 (0)