brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 0dab98c Raw
124 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect -convert-scf-to-emitc %s | FileCheck %s2// RUN: mlir-opt -allow-unregistered-dialect -convert-to-emitc="filter-dialects=scf" %s | FileCheck %s3 4// CHECK-LABEL:   func.func @switch_no_result(5// CHECK-SAME:                                %[[ARG_0:.*]]: index) {6// CHECK:           %[[VAL_0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : index to !emitc.size_t7// CHECK:           emitc.switch %[[VAL_0]]8// CHECK:           case 2 {9// CHECK:             %[[VAL_1:.*]] = arith.constant 10 : i3210// CHECK:             yield11// CHECK:           }12// CHECK:           case 5 {13// CHECK:             %[[VAL_2:.*]] = arith.constant 20 : i3214// CHECK:             yield15// CHECK:           }16// CHECK:           default {17// CHECK:             %[[VAL_3:.*]] = arith.constant 30 : i3218// CHECK:           }19// CHECK:           return20// CHECK:         }21func.func @switch_no_result(%arg0 : index) {22    scf.index_switch %arg023    case 2 {24      %1 = arith.constant 10 : i3225      scf.yield26    }27    case 5 {28      %2 = arith.constant 20 : i3229      scf.yield30    }31    default {32      %3 = arith.constant 30 : i3233    }34  return35}36 37// CHECK-LABEL:   func.func @switch_one_result(38// CHECK-SAME:                                 %[[ARG_0:.*]]: index) {39// CHECK:           %[[VAL_0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : index to !emitc.size_t40// CHECK:           %[[VAL_1:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>41// CHECK:           emitc.switch %[[VAL_0]]42// CHECK:           case 2 {43// CHECK:             %[[VAL_2:.*]] = arith.constant 10 : i3244// CHECK:             assign %[[VAL_2]] : i32 to %[[VAL_1]] : <i32>45// CHECK:             yield46// CHECK:           }47// CHECK:           case 5 {48// CHECK:             %[[VAL_3:.*]] = arith.constant 20 : i3249// CHECK:             assign %[[VAL_3]] : i32 to %[[VAL_1]] : <i32>50// CHECK:             yield51// CHECK:           }52// CHECK:           default {53// CHECK:             %[[VAL_4:.*]] = arith.constant 30 : i3254// CHECK:             assign %[[VAL_4]] : i32 to %[[VAL_1]] : <i32>55// CHECK:           }56// CHECK:           return57// CHECK:         }58func.func @switch_one_result(%arg0 : index) {59    %0 = scf.index_switch %arg0 -> i3260    case 2 {61      %1 = arith.constant 10 : i3262      scf.yield %1 : i3263    }64    case 5 {65      %2 = arith.constant 20 : i3266      scf.yield %2 : i3267    }68    default {69      %3 = arith.constant 30 : i3270      scf.yield %3 : i3271    }72  return73}74 75// CHECK-LABEL:   func.func @switch_two_results(76// CHECK-SAME:                                  %[[ARG_0:.*]]: index) -> (i32, f32) {77// CHECK:           %[[VAL_0:.*]] = builtin.unrealized_conversion_cast %[[ARG_0]] : index to !emitc.size_t78// CHECK:           %[[VAL_1:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>79// CHECK:           %[[VAL_2:.*]] = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<f32>80// CHECK:           emitc.switch %[[VAL_0]]81// CHECK:           case 2 {82// CHECK:             %[[VAL_3:.*]] = arith.constant 10 : i3283// CHECK:             %[[VAL_4:.*]] = arith.constant 1.200000e+00 : f3284// CHECK:             assign %[[VAL_3]] : i32 to %[[VAL_1]] : <i32>85// CHECK:             assign %[[VAL_4]] : f32 to %[[VAL_2]] : <f32>86// CHECK:             yield87// CHECK:           }88// CHECK:           case 5 {89// CHECK:             %[[VAL_5:.*]] = arith.constant 20 : i3290// CHECK:             %[[VAL_6:.*]] = arith.constant 2.400000e+00 : f3291// CHECK:             assign %[[VAL_5]] : i32 to %[[VAL_1]] : <i32>92// CHECK:             assign %[[VAL_6]] : f32 to %[[VAL_2]] : <f32>93// CHECK:             yield94// CHECK:           }95// CHECK:           default {96// CHECK:             %[[VAL_7:.*]] = arith.constant 30 : i3297// CHECK:             %[[VAL_8:.*]] = arith.constant 3.600000e+00 : f3298// CHECK:             assign %[[VAL_7]] : i32 to %[[VAL_1]] : <i32>99// CHECK:             assign %[[VAL_8]] : f32 to %[[VAL_2]] : <f32>100// CHECK:           }101// CHECK:           %[[RES_1:.*]] = emitc.load %[[VAL_1]] : <i32>102// CHECK:           %[[RES_2:.*]] = emitc.load %[[VAL_2]] : <f32>103// CHECK:           return %[[RES_1]], %[[RES_2]] : i32, f32104// CHECK:         }105func.func @switch_two_results(%arg0 : index) -> (i32, f32) {106    %0, %1 = scf.index_switch %arg0 -> i32, f32107    case 2 {108      %2 = arith.constant 10 : i32109      %3 = arith.constant 1.2 : f32110      scf.yield %2, %3 : i32, f32111    }112    case 5 {113      %4 = arith.constant 20 : i32114      %5 = arith.constant 2.4 : f32115      scf.yield %4, %5 : i32, f32116    }117    default {118      %6 = arith.constant 30 : i32119      %7 = arith.constant 3.6 : f32120      scf.yield %6, %7 : i32, f32121    }122    return %0, %1 : i32, f32123}124