brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 7c78211 Raw
84 lines · plain
1// RUN: mlir-opt %s -convert-cf-to-llvm -split-input-file | FileCheck %s2 3// Unstructured control flow is converted, but the enclosing op is not4// converted.5 6// CHECK-LABEL: func.func @cf_br(7//  CHECK-SAME:     %[[arg0:.*]]: index) -> index {8//       CHECK:   %[[cast0:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : index to i649//       CHECK:   llvm.br ^[[bb1:.*]](%[[cast0]] : i64)10//       CHECK: ^[[bb1]](%[[arg1:.*]]: i64):11//       CHECK:   %[[cast1:.*]] = builtin.unrealized_conversion_cast %[[arg1]] : i64 to index12//       CHECK:   return %[[cast1]] : index13//       CHECK: }14func.func @cf_br(%arg0: index) -> index {15  cf.br ^bb1(%arg0 : index)16^bb1(%arg1: index):17  return %arg1 : index18}19 20// -----21 22// func.func and func.return types match. No unrealized_conversion_cast is23// needed.24 25// CHECK-LABEL: func.func @cf_br_type_match(26//  CHECK-SAME:     %[[arg0:.*]]: i64) -> i64 {27//       CHECK:   llvm.br ^[[bb1:.*]](%[[arg0:.*]] : i64)28//       CHECK: ^[[bb1]](%[[arg1:.*]]: i64):29//       CHECK:   return %[[arg1]] : i6430//       CHECK: }31func.func @cf_br_type_match(%arg0: i64) -> i64 {32  cf.br ^bb1(%arg0 : i64)33^bb1(%arg1: i64):34  return %arg1 : i6435}36 37// -----38 39// Test case for cf.cond_br.40 41//   CHECK-LABEL: func.func @cf_cond_br42// CHECK-COUNT-2:   unrealized_conversion_cast {{.*}} : index to i6443//         CHECK:   llvm.cond_br %{{.*}}, ^{{.*}}(%{{.*}} : i64), ^{{.*}}(%{{.*}} : i64)44//         CHECK: ^{{.*}}(%{{.*}}: i64):45//         CHECK:   unrealized_conversion_cast {{.*}} : i64 to index46//         CHECK: ^{{.*}}(%{{.*}}: i64):47//         CHECK:   unrealized_conversion_cast {{.*}} : i64 to index48func.func @cf_cond_br(%cond: i1, %a: index, %b: index) -> index {49  cf.cond_br %cond, ^bb1(%a : index), ^bb2(%b : index)50^bb1(%arg1: index):51  return %arg1 : index52^bb2(%arg2: index):53  return %arg2 : index54}55 56// -----57 58// Unreachable block (and IR in general) is not converted during a dialect59// conversion.60 61// CHECK-LABEL: func.func @unreachable_block()62//       CHECK:   return63//       CHECK: ^[[bb1:.*]](%[[arg0:.*]]: index):64//       CHECK:   cf.br ^[[bb1]](%[[arg0]] : index)65func.func @unreachable_block() {66  return67^bb1(%arg0: index):68  cf.br ^bb1(%arg0 : index)69}70 71// -----72 73// Test case for cf.cond_br with weights.74 75// CHECK-LABEL:   func.func @cf_cond_br_with_weights(76func.func @cf_cond_br_with_weights(%cond: i1, %a: index, %b: index) -> index {77// CHECK:           llvm.cond_br %{{.*}} weights([90, 10]), ^bb1(%{{.*}} : i64), ^bb2(%{{.*}} : i64)78  cf.cond_br %cond, ^bb1(%a : index), ^bb2(%b : index) {branch_weights = array<i32: 90, 10>}79^bb1(%arg1: index):80  return %arg1 : index81^bb2(%arg2: index):82  return %arg2 : index83}84