xref: /llvm-project/mlir/test/Target/Cpp/stdops.mlir (revision 5cc228148e800b75adfc778f8b5fbace04478dd3)
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
4func.func @std_call() {
5  %0 = call @one_result () : () -> i32
6  %1 = call @one_result () : () -> i32
7  return
8}
9// CPP-DEFAULT: void std_call() {
10// CPP-DEFAULT-NEXT: int32_t [[V0:[^ ]*]] = one_result();
11// CPP-DEFAULT-NEXT: int32_t [[V1:[^ ]*]] = one_result();
12
13// CPP-DECLTOP: void std_call() {
14// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]];
15// CPP-DECLTOP-NEXT: int32_t [[V1:[^ ]*]];
16// CPP-DECLTOP-NEXT: [[V0]] = one_result();
17// CPP-DECLTOP-NEXT: [[V1]] = one_result();
18
19
20func.func @std_call_two_results() {
21  %0:2 = call @two_results () : () -> (i32, f32)
22  %1:2 = call @two_results () : () -> (i32, f32)
23  return
24}
25// CPP-DEFAULT: void std_call_two_results() {
26// CPP-DEFAULT-NEXT: int32_t [[V1:[^ ]*]];
27// CPP-DEFAULT-NEXT: float [[V2:[^ ]*]];
28// CPP-DEFAULT-NEXT: std::tie([[V1]], [[V2]]) = two_results();
29// CPP-DEFAULT-NEXT: int32_t [[V3:[^ ]*]];
30// CPP-DEFAULT-NEXT: float [[V4:[^ ]*]];
31// CPP-DEFAULT-NEXT: std::tie([[V3]], [[V4]]) = two_results();
32
33// CPP-DECLTOP: void std_call_two_results() {
34// CPP-DECLTOP-NEXT: int32_t [[V1:[^ ]*]];
35// CPP-DECLTOP-NEXT: float [[V2:[^ ]*]];
36// CPP-DECLTOP-NEXT: int32_t [[V3:[^ ]*]];
37// CPP-DECLTOP-NEXT: float [[V4:[^ ]*]];
38// CPP-DECLTOP-NEXT: std::tie([[V1]], [[V2]]) = two_results();
39// CPP-DECLTOP-NEXT: std::tie([[V3]], [[V4]]) = two_results();
40
41
42func.func @one_result() -> i32 {
43  %0 = "emitc.constant"() <{value = 0 : i32}> : () -> i32
44  return %0 : i32
45}
46// CPP-DEFAULT: int32_t one_result() {
47// CPP-DEFAULT-NEXT: int32_t [[V0:[^ ]*]] = 0;
48// CPP-DEFAULT-NEXT: return [[V0]];
49
50// CPP-DECLTOP: int32_t one_result() {
51// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]];
52// CPP-DECLTOP-NEXT: [[V0]] = 0;
53// CPP-DECLTOP-NEXT: return [[V0]];
54
55
56func.func @two_results() -> (i32, f32) {
57  %0 = "emitc.constant"() <{value = 0 : i32}> : () -> i32
58  %1 = "emitc.constant"() <{value = 1.0 : f32}> : () -> f32
59  return %0, %1 : i32, f32
60}
61// CPP-DEFAULT: std::tuple<int32_t, float> two_results() {
62// CPP-DEFAULT: int32_t [[V0:[^ ]*]] = 0;
63// CPP-DEFAULT: float [[V1:[^ ]*]] = 1.000000000e+00f;
64// CPP-DEFAULT: return std::make_tuple([[V0]], [[V1]]);
65
66// CPP-DECLTOP: std::tuple<int32_t, float> two_results() {
67// CPP-DECLTOP: int32_t [[V0:[^ ]*]];
68// CPP-DECLTOP: float [[V1:[^ ]*]];
69// CPP-DECLTOP: [[V0]] = 0;
70// CPP-DECLTOP: [[V1]] = 1.000000000e+00f;
71// CPP-DECLTOP: return std::make_tuple([[V0]], [[V1]]);
72
73
74func.func @single_return_statement(%arg0 : i32) -> i32 {
75  return %arg0 : i32
76}
77// CPP-DEFAULT: int32_t single_return_statement(int32_t [[V0:[^ ]*]]) {
78// CPP-DEFAULT-NEXT: return [[V0]];
79
80// CPP-DECLTOP: int32_t single_return_statement(int32_t [[V0:[^ ]*]]) {
81// CPP-DECLTOP-NEXT: return [[V0]];
82