1// RUN: mlir-opt -allow-unregistered-dialect -convert-scf-to-emitc %s | FileCheck %s 2 3// CHECK-LABEL: func.func @switch_no_result( 4// CHECK-SAME: %[[ARG_0:.*]]: index) { 5// CHECK: %[[VAL_0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : index to !emitc.size_t 6// CHECK: emitc.switch %[[VAL_0]] 7// CHECK: case 2 { 8// CHECK: %[[VAL_1:.*]] = arith.constant 10 : i32 9// CHECK: yield 10// CHECK: } 11// CHECK: case 5 { 12// CHECK: %[[VAL_2:.*]] = arith.constant 20 : i32 13// CHECK: yield 14// CHECK: } 15// CHECK: default { 16// CHECK: %[[VAL_3:.*]] = arith.constant 30 : i32 17// CHECK: } 18// CHECK: return 19// CHECK: } 20func.func @switch_no_result(%arg0 : index) { 21 scf.index_switch %arg0 22 case 2 { 23 %1 = arith.constant 10 : i32 24 scf.yield 25 } 26 case 5 { 27 %2 = arith.constant 20 : i32 28 scf.yield 29 } 30 default { 31 %3 = arith.constant 30 : i32 32 } 33 return 34} 35 36// CHECK-LABEL: func.func @switch_one_result( 37// CHECK-SAME: %[[ARG_0:.*]]: index) { 38// CHECK: %[[VAL_0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : index to !emitc.size_t 39// CHECK: %[[VAL_1:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32> 40// CHECK: emitc.switch %[[VAL_0]] 41// CHECK: case 2 { 42// CHECK: %[[VAL_2:.*]] = arith.constant 10 : i32 43// CHECK: assign %[[VAL_2]] : i32 to %[[VAL_1]] : <i32> 44// CHECK: yield 45// CHECK: } 46// CHECK: case 5 { 47// CHECK: %[[VAL_3:.*]] = arith.constant 20 : i32 48// CHECK: assign %[[VAL_3]] : i32 to %[[VAL_1]] : <i32> 49// CHECK: yield 50// CHECK: } 51// CHECK: default { 52// CHECK: %[[VAL_4:.*]] = arith.constant 30 : i32 53// CHECK: assign %[[VAL_4]] : i32 to %[[VAL_1]] : <i32> 54// CHECK: } 55// CHECK: return 56// CHECK: } 57func.func @switch_one_result(%arg0 : index) { 58 %0 = scf.index_switch %arg0 -> i32 59 case 2 { 60 %1 = arith.constant 10 : i32 61 scf.yield %1 : i32 62 } 63 case 5 { 64 %2 = arith.constant 20 : i32 65 scf.yield %2 : i32 66 } 67 default { 68 %3 = arith.constant 30 : i32 69 scf.yield %3 : i32 70 } 71 return 72} 73 74// CHECK-LABEL: func.func @switch_two_results( 75// CHECK-SAME: %[[ARG_0:.*]]: index) -> (i32, f32) { 76// CHECK: %[[VAL_0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : index to !emitc.size_t 77// CHECK: %[[VAL_1:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32> 78// CHECK: %[[VAL_2:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32> 79// CHECK: emitc.switch %[[VAL_0]] 80// CHECK: case 2 { 81// CHECK: %[[VAL_3:.*]] = arith.constant 10 : i32 82// CHECK: %[[VAL_4:.*]] = arith.constant 1.200000e+00 : f32 83// CHECK: assign %[[VAL_3]] : i32 to %[[VAL_1]] : <i32> 84// CHECK: assign %[[VAL_4]] : f32 to %[[VAL_2]] : <f32> 85// CHECK: yield 86// CHECK: } 87// CHECK: case 5 { 88// CHECK: %[[VAL_5:.*]] = arith.constant 20 : i32 89// CHECK: %[[VAL_6:.*]] = arith.constant 2.400000e+00 : f32 90// CHECK: assign %[[VAL_5]] : i32 to %[[VAL_1]] : <i32> 91// CHECK: assign %[[VAL_6]] : f32 to %[[VAL_2]] : <f32> 92// CHECK: yield 93// CHECK: } 94// CHECK: default { 95// CHECK: %[[VAL_7:.*]] = arith.constant 30 : i32 96// CHECK: %[[VAL_8:.*]] = arith.constant 3.600000e+00 : f32 97// CHECK: assign %[[VAL_7]] : i32 to %[[VAL_1]] : <i32> 98// CHECK: assign %[[VAL_8]] : f32 to %[[VAL_2]] : <f32> 99// CHECK: } 100// CHECK: %[[RES_1:.*]] = emitc.load %[[VAL_1]] : <i32> 101// CHECK: %[[RES_2:.*]] = emitc.load %[[VAL_2]] : <f32> 102// CHECK: return %[[RES_1]], %[[RES_2]] : i32, f32 103// CHECK: } 104func.func @switch_two_results(%arg0 : index) -> (i32, f32) { 105 %0, %1 = scf.index_switch %arg0 -> i32, f32 106 case 2 { 107 %2 = arith.constant 10 : i32 108 %3 = arith.constant 1.2 : f32 109 scf.yield %2, %3 : i32, f32 110 } 111 case 5 { 112 %4 = arith.constant 20 : i32 113 %5 = arith.constant 2.4 : f32 114 scf.yield %4, %5 : i32, f32 115 } 116 default { 117 %6 = arith.constant 30 : i32 118 %7 = arith.constant 3.6 : f32 119 scf.yield %6, %7 : i32, f32 120 } 121 return %0, %1 : i32, f32 122} 123