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 @std_constant() { 5 %c0 = constant 0 : i32 6 %c1 = constant 2 : index 7 %c2 = constant 2.0 : f32 8 %c3 = constant dense<0> : tensor<i32> 9 %c4 = constant dense<[0, 1]> : tensor<2xindex> 10 %c5 = constant dense<[[0.0, 1.0], [2.0, 3.0]]> : tensor<2x2xf32> 11 return 12} 13// CPP-DEFAULT: void std_constant() { 14// CPP-DEFAULT-NEXT: int32_t [[V0:[^ ]*]] = 0; 15// CPP-DEFAULT-NEXT: size_t [[V1:[^ ]*]] = 2; 16// CPP-DEFAULT-NEXT: float [[V2:[^ ]*]] = (float)2.000000000e+00; 17// CPP-DEFAULT-NEXT: Tensor<int32_t> [[V3:[^ ]*]] = {0}; 18// CPP-DEFAULT-NEXT: Tensor<size_t, 2> [[V4:[^ ]*]] = {0, 1}; 19// CPP-DEFAULT-NEXT: Tensor<float, 2, 2> [[V5:[^ ]*]] = {(float)0.0e+00, (float)1.000000000e+00, (float)2.000000000e+00, (float)3.000000000e+00}; 20 21// CPP-DECLTOP: void std_constant() { 22// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]]; 23// CPP-DECLTOP-NEXT: size_t [[V1:[^ ]*]]; 24// CPP-DECLTOP-NEXT: float [[V2:[^ ]*]]; 25// CPP-DECLTOP-NEXT: Tensor<int32_t> [[V3:[^ ]*]]; 26// CPP-DECLTOP-NEXT: Tensor<size_t, 2> [[V4:[^ ]*]]; 27// CPP-DECLTOP-NEXT: Tensor<float, 2, 2> [[V5:[^ ]*]]; 28// CPP-DECLTOP-NEXT: [[V0]] = 0; 29// CPP-DECLTOP-NEXT: [[V1]] = 2; 30// CPP-DECLTOP-NEXT: [[V2]] = (float)2.000000000e+00; 31// CPP-DECLTOP-NEXT: [[V3]] = {0}; 32// CPP-DECLTOP-NEXT: [[V4]] = {0, 1}; 33// CPP-DECLTOP-NEXT: [[V5]] = {(float)0.0e+00, (float)1.000000000e+00, (float)2.000000000e+00, (float)3.000000000e+00}; 34 35func @std_call() { 36 %0 = call @one_result () : () -> i32 37 %1 = call @one_result () : () -> i32 38 return 39} 40// CPP-DEFAULT: void std_call() { 41// CPP-DEFAULT-NEXT: int32_t [[V0:[^ ]*]] = one_result(); 42// CPP-DEFAULT-NEXT: int32_t [[V1:[^ ]*]] = one_result(); 43 44// CPP-DECLTOP: void std_call() { 45// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]]; 46// CPP-DECLTOP-NEXT: int32_t [[V1:[^ ]*]]; 47// CPP-DECLTOP-NEXT: [[V0]] = one_result(); 48// CPP-DECLTOP-NEXT: [[V1]] = one_result(); 49 50 51func @std_call_two_results() { 52 %c = constant 0 : i8 53 %0:2 = call @two_results () : () -> (i32, f32) 54 %1:2 = call @two_results () : () -> (i32, f32) 55 return 56} 57// CPP-DEFAULT: void std_call_two_results() { 58// CPP-DEFAULT-NEXT: int8_t [[V0:[^ ]*]] = 0; 59// CPP-DEFAULT-NEXT: int32_t [[V1:[^ ]*]]; 60// CPP-DEFAULT-NEXT: float [[V2:[^ ]*]]; 61// CPP-DEFAULT-NEXT: std::tie([[V1]], [[V2]]) = two_results(); 62// CPP-DEFAULT-NEXT: int32_t [[V3:[^ ]*]]; 63// CPP-DEFAULT-NEXT: float [[V4:[^ ]*]]; 64// CPP-DEFAULT-NEXT: std::tie([[V3]], [[V4]]) = two_results(); 65 66// CPP-DECLTOP: void std_call_two_results() { 67// CPP-DECLTOP-NEXT: int8_t [[V0:[^ ]*]]; 68// CPP-DECLTOP-NEXT: int32_t [[V1:[^ ]*]]; 69// CPP-DECLTOP-NEXT: float [[V2:[^ ]*]]; 70// CPP-DECLTOP-NEXT: int32_t [[V3:[^ ]*]]; 71// CPP-DECLTOP-NEXT: float [[V4:[^ ]*]]; 72// CPP-DECLTOP-NEXT: [[V0]] = 0; 73// CPP-DECLTOP-NEXT: std::tie([[V1]], [[V2]]) = two_results(); 74// CPP-DECLTOP-NEXT: std::tie([[V3]], [[V4]]) = two_results(); 75 76 77func @one_result() -> i32 { 78 %0 = constant 0 : i32 79 return %0 : i32 80} 81// CPP-DEFAULT: int32_t one_result() { 82// CPP-DEFAULT-NEXT: int32_t [[V0:[^ ]*]] = 0; 83// CPP-DEFAULT-NEXT: return [[V0]]; 84 85// CPP-DECLTOP: int32_t one_result() { 86// CPP-DECLTOP-NEXT: int32_t [[V0:[^ ]*]]; 87// CPP-DECLTOP-NEXT: [[V0]] = 0; 88// CPP-DECLTOP-NEXT: return [[V0]]; 89 90 91func @two_results() -> (i32, f32) { 92 %0 = constant 0 : i32 93 %1 = constant 1.0 : f32 94 return %0, %1 : i32, f32 95} 96// CPP-DEFAULT: std::tuple<int32_t, float> two_results() { 97// CPP-DEFAULT: int32_t [[V0:[^ ]*]] = 0; 98// CPP-DEFAULT: float [[V1:[^ ]*]] = (float)1.000000000e+00; 99// CPP-DEFAULT: return std::make_tuple([[V0]], [[V1]]); 100 101// CPP-DECLTOP: std::tuple<int32_t, float> two_results() { 102// CPP-DECLTOP: int32_t [[V0:[^ ]*]]; 103// CPP-DECLTOP: float [[V1:[^ ]*]]; 104// CPP-DECLTOP: [[V0]] = 0; 105// CPP-DECLTOP: [[V1]] = (float)1.000000000e+00; 106// CPP-DECLTOP: return std::make_tuple([[V0]], [[V1]]); 107 108 109func @single_return_statement(%arg0 : i32) -> i32 { 110 return %arg0 : i32 111} 112// CPP-DEFAULT: int32_t single_return_statement(int32_t [[V0:[^ ]*]]) { 113// CPP-DEFAULT-NEXT: return [[V0]]; 114 115// CPP-DECLTOP: int32_t single_return_statement(int32_t [[V0:[^ ]*]]) { 116// CPP-DECLTOP-NEXT: return [[V0]]; 117