xref: /llvm-project/mlir/test/Dialect/ControlFlow/ops.mlir (revision 7e87d03b45f3ca0f6d9c09e8e9090329cc84592e)
1// RUN: mlir-opt %s | mlir-opt | FileCheck %s
2// RUN: mlir-opt %s --mlir-print-op-generic | mlir-opt | FileCheck %s
3
4// CHECK-LABEL: @assert
5func.func @assert(%arg : i1) {
6  cf.assert %arg, "Some message in case this assertion fails."
7  return
8}
9
10// CHECK-LABEL: func @switch(
11func.func @switch(%flag : i32, %caseOperand : i32) {
12  cf.switch %flag : i32, [
13    default: ^bb1(%caseOperand : i32),
14    42: ^bb2(%caseOperand : i32),
15    43: ^bb3(%caseOperand : i32)
16  ]
17
18  ^bb1(%bb1arg : i32):
19    return
20  ^bb2(%bb2arg : i32):
21    return
22  ^bb3(%bb3arg : i32):
23    return
24}
25
26// CHECK-LABEL: func @switch_i64(
27func.func @switch_i64(%flag : i64, %caseOperand : i32) {
28  cf.switch %flag : i64, [
29    default: ^bb1(%caseOperand : i32),
30    42: ^bb2(%caseOperand : i32),
31    43: ^bb3(%caseOperand : i32)
32  ]
33
34  ^bb1(%bb1arg : i32):
35    return
36  ^bb2(%bb2arg : i32):
37    return
38  ^bb3(%bb3arg : i32):
39    return
40}
41
42// CHECK-LABEL: func @switch_result_number
43func.func @switch_result_number(%arg0: i32) {
44  %0:2 = "test.op_with_two_results"() : () -> (i32, i32)
45  cf.switch %arg0 : i32, [
46    default: ^bb2,
47    0: ^bb1(%0#0 : i32)
48  ]
49  ^bb1(%1: i32):
50    return
51  ^bb2:
52    return
53}
54