aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/IR/region.mlir
blob: 0b959915d6bbbe8087873582fc24652faa07a4f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics | FileCheck %s

//===----------------------------------------------------------------------===//
// Test the number of regions
//===----------------------------------------------------------------------===//

func.func @correct_number_of_regions() {
    // CHECK: test.two_region_op
    "test.two_region_op"()(
      {"work"() : () -> ()},
      {"work"() : () -> ()}
    ) : () -> ()
    return
}

// -----

func.func @missing_regions() {
    // expected-error@+1 {{expected 2 regions}}
    "test.two_region_op"()(
      {"work"() : () -> ()}
    ) : () -> ()
    return
}

// -----

func.func @extra_regions() {
    // expected-error@+1 {{expected 2 regions}}
    "test.two_region_op"()(
      {"work"() : () -> ()},
      {"work"() : () -> ()},
      {"work"() : () -> ()}
    ) : () -> ()
    return
}

// -----

//===----------------------------------------------------------------------===//
// Test SizedRegion
//===----------------------------------------------------------------------===//

func.func @unnamed_region_has_wrong_number_of_blocks() {
    // expected-error@+1 {{region #1 failed to verify constraint: region with 1 blocks}}
    "test.sized_region_op"() (
    {
        "work"() : () -> ()
        cf.br ^next1
      ^next1:
        "work"() : () -> ()
    },
    {
        "work"() : () -> ()
        cf.br ^next2
      ^next2:
        "work"() : () -> ()
    }) : () -> ()
    return
}

// -----

// Test region name in error message
func.func @named_region_has_wrong_number_of_blocks() {
    // expected-error@+1 {{region #0 ('my_region') failed to verify constraint: region with 2 blocks}}
    "test.sized_region_op"() (
    {
        "work"() : () -> ()
    },
    {
        "work"() : () -> ()
    }) : () -> ()
    return
}

// -----

// Region with single block and not terminator.
// CHECK: unregistered_without_terminator
"test.unregistered_without_terminator"() ({
  ^bb0:
}) : () -> ()

// -----

// CHECK: test.single_no_terminator_op
"test.single_no_terminator_op"() (
  {
    %foo = arith.constant 1 : i32
  }
) : () -> ()

// CHECK: test.variadic_no_terminator_op
"test.variadic_no_terminator_op"() (
  {
    %foo = arith.constant 1 : i32
  },
  {
    %bar = arith.constant 1 : i32
  }
) : () -> ()

// CHECK: test.single_no_terminator_custom_asm_op
// CHECK-NEXT: important_dont_drop
test.single_no_terminator_custom_asm_op {
  "important_dont_drop"() : () -> ()
}