1 ! Test forall scheduling analysis from lower-hlfir-ordered-assignments pass.
2 ! The printed output is done via LLVM_DEBUG, hence the "asserts" requirement.
3 ! This test test that conflicting actions are not scheduled to be evaluated
4 ! in the same loops (same run id).
6 ! RUN: bbc -hlfir -o - -pass-pipeline="builtin.module(lower-hlfir-ordered-assignments)" --debug-only=flang-ordered-assignment -flang-dbg-order-assignment-schedule-only %s 2>&1 | FileCheck %s
9 subroutine no_conflict(x
)
11 forall(i
=1:10) x(i
) = i
13 !CHECK-LABEL: ------------ scheduling forall in _QPno_conflict ------------
14 !CHECK-NEXT: run 1 evaluate: forall/region_assign1
16 subroutine rhs_lhs_overlap(x
)
18 forall(i
=1:10) x(i
) = x(11-i
)
20 !CHECK-LABEL: ------------ scheduling forall in _QPrhs_lhs_overlap ------------
21 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?xf32>>' at index: 0 W:<block argument> of type '!fir.box<!fir.array<?xf32>>' at index: 0
22 !CHECK-NEXT: run 1 save : forall/region_assign1/rhs
23 !CHECK-NEXT: run 2 evaluate: forall/region_assign1
25 subroutine no_rhs_lhs_overlap(x
, y
)
27 forall(i
=1:10) x(i
) = y(i
)
29 !CHECK-LABEL: ------------ scheduling forall in _QPno_rhs_lhs_overlap ------------
30 !CHECK-NEXT: run 1 evaluate: forall/region_assign1
32 subroutine no_rhs_lhs_overlap_2(x
)
34 forall(i
=1:10) x(i
) = y(i
)
36 !CHECK-LABEL: ------------ scheduling forall in _QPno_rhs_lhs_overlap_2 ------------
37 !CHECK-NEXT: run 1 evaluate: forall/region_assign1
39 subroutine no_rhs_lhs_overlap_3()
41 forall(i
=1:10) x(i
) = y(i
)
43 !CHECK-LABEL: ------------ scheduling forall in _QPno_rhs_lhs_overlap_3 ------------
44 !CHECK-NEXT: run 1 evaluate: forall/region_assign1
46 subroutine array_expr_rhs_lhs_overlap(x
)
48 forall(i
=1:10) x(i
, :) = x(:, i
)*2
50 !CHECK-LABEL: ------------ scheduling forall in _QParray_expr_rhs_lhs_overlap ------------
51 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xf32>>' at index: 0 W:<block argument> of type '!fir.box<!fir.array<?x?xf32>>' at index: 0
52 !CHECK-NEXT: run 1 save : forall/region_assign1/rhs
53 !CHECK-NEXT: run 2 evaluate: forall/region_assign1
55 subroutine array_expr_no_rhs_lhs_overlap(x
, y
, z
)
56 real :: x(:, :), y(:, :), z(:, :)
57 forall(i
=1:10) x(i
, :) = y(:, i
) + z(i
, :)
59 !CHECK-LABEL: ------------ scheduling forall in _QParray_expr_no_rhs_lhs_overlap ------------
60 !CHECK-NEXT: run 1 evaluate: forall/region_assign1
62 subroutine rhs_lhs_overlap_2(x
, y
)
63 real, target
:: x(:), y(:)
64 forall(i
=1:10) x(i
) = y(i
)
66 !CHECK-LABEL: ------------ scheduling forall in _QPrhs_lhs_overlap_2 ------------
67 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?xf32>>' at index: 1 W:<block argument> of type '!fir.box<!fir.array<?xf32>>' at index: 0
68 !CHECK-NEXT: run 1 save : forall/region_assign1/rhs
69 !CHECK-NEXT: run 2 evaluate: forall/region_assign1
71 subroutine lhs_lhs_overlap(x
)
73 forall(i
=1:10) x(x(i
)) = i
75 !CHECK-LABEL: ------------ scheduling forall in _QPlhs_lhs_overlap ------------
76 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.ref<!fir.array<10xi32>>' at index: 0 W:<block argument> of type '!fir.ref<!fir.array<10xi32>>' at index: 0
77 !CHECK-NEXT: run 1 save : forall/region_assign1/lhs
78 !CHECK-NEXT: run 2 evaluate: forall/region_assign1
80 subroutine unknown_function_call(x
)
82 pure
real function foo(x
, i
)
83 integer, intent(in
) :: i
84 real, intent(in
) :: x(10)
88 forall(i
=1:10) x(i
) = foo(x
, i
)
90 !CHECK-LABEL: ------------ scheduling forall in _QPunknown_function_call ------------
91 !CHECK-NEXT: unknown effect: {{.*}} fir.call @_QPfoo
92 !CHECK-NEXT: unknown effect: {{.*}} fir.call @_QPfoo
93 !CHECK-NEXT: conflict: R/W: <unknown> W:<block argument> of type '!fir.ref<!fir.array<10xf32>>' at index: 0
94 !CHECK-NEXT: run 1 save : forall/region_assign1/rhs
95 !CHECK-NEXT: run 2 evaluate: forall/region_assign1
97 subroutine unknown_function_call2(x
)
99 pure
real function foo2(i
)
103 ! foo2 may read x since it is a target, even if it is pure,
104 ! if the actual argument of x is a module variable accessible
105 ! to foo via host association.
107 forall(i
=1:10) x(i
) = foo2(i
)
109 !CHECK-LABEL: ------------ scheduling forall in _QPunknown_function_call2 ------------
110 !CHECK-NEXT: unknown effect: {{.*}} fir.call @_QPfoo2(
111 !CHECK-NEXT: unknown effect: {{.*}} fir.call @_QPfoo2(
112 !CHECK-NEXT: conflict: R/W: <unknown> W:<block argument> of type '!fir.box<!fir.array<?xf32>>' at index: 0
113 !CHECK-NEXT: run 1 save : forall/region_assign1/rhs
114 !CHECK-NEXT: run 2 evaluate: forall/region_assign1
116 subroutine forall_mask_conflict(x
)
118 forall(i
=1:10, x(11-i
)>0) x(i
) = 42
120 !CHECK-LABEL: ------------ scheduling forall in _QPforall_mask_conflict ------------
121 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?xi32>>' at index: 0 W:<block argument> of type '!fir.box<!fir.array<?xi32>>' at index: 0
122 !CHECK-NEXT: run 1 save : forall/forall_mask1/mask
123 !CHECK-NEXT: run 2 evaluate: forall/forall_mask1/region_assign1
125 subroutine forall_ub_conflict(x
, y
)
133 !CHECK-LABEL: ------------ scheduling forall in _QPforall_ub_conflict ------------
134 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0 W:<block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0
135 !CHECK-NEXT: run 1 save : forall/forall1/ub
136 !CHECK-NEXT: run 2 evaluate: forall/forall1/region_assign1
138 subroutine sequential_assign(x
, y
)
139 integer :: x(:), y(:)
145 !CHECK-LABEL: ------------ scheduling forall in _QPsequential_assign ------------
146 !CHECK-NEXT: run 1 evaluate: forall/region_assign1
147 !CHECK-NEXT: run 2 evaluate: forall/region_assign2
149 subroutine loads_of_conlficts(x
, y
)
150 integer, target
:: x(:, :), y(:, :)
152 forall (j
=1:y(i
,i
)) x(x(i
, j
), j
) = y(i
, j
)
153 forall (j
=1:x(i
,i
), y(i
,i
)>0) y(x(i
, j
), j
) = 0
156 !CHECK-LABEL: ------------ scheduling forall in _QPloads_of_conlficts ------------
157 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 1 W:<block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0
158 !CHECK-NEXT: run 1 save : forall/forall1/ub
159 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 1 W:<block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0
160 !CHECK-NEXT: run 1 save : forall/forall1/region_assign1/rhs
161 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0 W:<block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0
162 !CHECK-NEXT: run 1 save : forall/forall1/region_assign1/lhs
163 !CHECK-NEXT: run 2 evaluate: forall/forall1/region_assign1
164 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0 W:<block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 1
165 !CHECK-NEXT: run 3 save : forall/forall2/ub
166 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 1 W:<block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 1
167 !CHECK-NEXT: run 3 save : forall/forall2/forall_mask1/mask
168 !CHECK-NEXT: conflict: R/W: <block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 0 W:<block argument> of type '!fir.box<!fir.array<?x?xi32>>' at index: 1
169 !CHECK-NEXT: run 3 save : forall/forall2/forall_mask1/region_assign1/lhs
170 !CHECK-NEXT: run 4 evaluate: forall/forall2/forall_mask1/region_assign1