1// RUN: mlir-opt -allow-unregistered-dialect %s -inline="disable-simplify" | FileCheck %s
2
3// Basic test that functions within affine operations are inlined.
4func @func_with_affine_ops(%N: index) {
5  %c = constant 200 : index
6  affine.for %i = 1 to 10 {
7    affine.if affine_set<(i)[N] : (i - 2 >= 0, 4 - i >= 0)>(%i)[%c]  {
8      %w = affine.apply affine_map<(d0,d1)[s0] -> (d0+d1+s0)> (%i, %i) [%N]
9    }
10  }
11  return
12}
13
14// CHECK-LABEL: func @inline_with_affine_ops
15func @inline_with_affine_ops() {
16  %c = constant 1 : index
17
18  // CHECK: affine.for
19  // CHECK-NEXT: affine.if
20  // CHECK-NEXT: affine.apply
21  // CHECK-NOT: call
22  call @func_with_affine_ops(%c) : (index) -> ()
23  return
24}
25
26// CHECK-LABEL: func @not_inline_in_affine_op
27func @not_inline_in_affine_op() {
28  %c = constant 1 : index
29
30  // CHECK-NOT: affine.if
31  // CHECK: call
32  affine.for %i = 1 to 10 {
33    call @func_with_affine_ops(%c) : (index) -> ()
34  }
35  return
36}
37
38// -----
39
40// Test when an invalid operation is nested in an affine op.
41func @func_with_invalid_nested_op() {
42  affine.for %i = 1 to 10 {
43    "foo.opaque"() : () -> ()
44  }
45  return
46}
47
48// CHECK-LABEL: func @not_inline_invalid_nest_op
49func @not_inline_invalid_nest_op() {
50  // CHECK: call @func_with_invalid_nested_op
51  call @func_with_invalid_nested_op() : () -> ()
52  return
53}
54
55// -----
56
57// Test that calls are not inlined into affine structures.
58func @func_noop() {
59  return
60}
61
62// CHECK-LABEL: func @not_inline_into_affine_ops
63func @not_inline_into_affine_ops() {
64  // CHECK: call @func_noop
65  affine.for %i = 1 to 10 {
66    call @func_noop() : () -> ()
67  }
68  return
69}
70