Skip to content

Commit 84c1825

Browse files
author
Razvan Lupusoru
committed
Add TODO for unstructured in kernels
1 parent c33681d commit 84c1825

File tree

3 files changed

+103
-68
lines changed

3 files changed

+103
-68
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5018,9 +5018,18 @@ mlir::Operation *Fortran::lower::genOpenACCLoopFromDoConstruct(
50185018
// TODO: There may be other strategies that can be employed such
50195019
// as generating acc.private for the loop variables without attaching
50205020
// them to acc.loop.
5021-
if (eval.lowerAsUnstructured())
5022-
TODO(converter.getCurrentLocation(),
5023-
"unstructured do loops in acc regions");
5021+
// For now - generate a not-yet-implemented message because without
5022+
// privatizing the induction variable, the loop may not execute correctly.
5023+
// Only do this for `acc kernels` because in `acc parallel`, scalars end
5024+
// up as implicitly firstprivate.
5025+
if (eval.lowerAsUnstructured()) {
5026+
if (mlir::isa_and_present<mlir::acc::KernelsOp>(
5027+
mlir::acc::getEnclosingComputeOp(
5028+
converter.getFirOpBuilder().getRegion())))
5029+
TODO(converter.getCurrentLocation(),
5030+
"unstructured do loop in acc kernels");
5031+
return nullptr;
5032+
}
50245033

50255034
// Open up a new scope for the loop variables.
50265035
localSymbols.pushScope();
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
! RUN: split-file %s %t
2+
! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/do_loop_with_stop.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK1
3+
! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/do_loop_with_cycle_goto.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK2
4+
! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/nested_goto_loop.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK3
5+
! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/nested_loop_with_inner_goto.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK4
6+
7+
//--- do_loop_with_stop.f90
8+
9+
subroutine do_loop_with_stop()
10+
integer :: i
11+
integer, parameter :: n = 10
12+
real, dimension(n) :: a, b
13+
14+
!$acc kernels
15+
do i = 1, n
16+
a(i) = b(i) + 1.0
17+
if (i == 5) stop
18+
end do
19+
!$acc end kernels
20+
21+
! CHECK1: not yet implemented: unstructured do loop in acc kernels
22+
23+
end subroutine
24+
25+
//--- do_loop_with_cycle_goto.f90
26+
27+
subroutine do_loop_with_cycle_goto()
28+
integer :: i
29+
integer, parameter :: n = 10
30+
real, dimension(n) :: a, b
31+
32+
! Do loop with cycle and goto - unstructured control flow is not converted.
33+
!$acc kernels
34+
do i = 1, n
35+
if (i == 3) cycle
36+
a(i) = b(i) + 1.0
37+
if (i == 7) goto 200
38+
a(i) = a(i) * 2.0
39+
end do
40+
200 continue
41+
!$acc end kernels
42+
43+
! CHECK2: not yet implemented: unstructured do loop in acc kernels
44+
45+
end subroutine
46+
47+
//--- nested_goto_loop.f90
48+
49+
subroutine nested_goto_loop()
50+
integer :: i, j
51+
integer, parameter :: n = 10, m = 5
52+
real, dimension(n,m) :: a, b
53+
54+
! Nested loop with goto from inner to outer - should NOT convert to acc.loop
55+
!$acc kernels
56+
do i = 1, n
57+
do j = 1, m
58+
a(i,j) = b(i,j) + 1.0
59+
if (i * j > 20) goto 300 ! Exit both loops
60+
end do
61+
end do
62+
300 continue
63+
!$acc end kernels
64+
65+
! CHECK3: not yet implemented: unstructured do loop in acc kernels
66+
67+
end subroutine
68+
69+
//--- nested_loop_with_inner_goto.f90
70+
71+
subroutine nested_loop_with_inner_goto()
72+
integer :: ii = 0, jj = 0
73+
integer, parameter :: nn = 3
74+
real, dimension(nn, nn) :: aa
75+
76+
aa = -1
77+
78+
! Nested loop with goto from inner loop - unstructured control flow is not converted.
79+
!$acc kernels
80+
do ii = 1, nn
81+
do jj = 1, nn
82+
if (jj > 1) goto 300
83+
aa(jj, ii) = 1337
84+
end do
85+
300 continue
86+
end do
87+
!$acc end kernels
88+
89+
! CHECK4: not yet implemented: unstructured do loop in acc kernels
90+
91+
end subroutine

flang/test/Lower/OpenACC/do-loops-to-acc-loops.f90

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -245,71 +245,6 @@ subroutine infinite_loop_no_iv()
245245

246246
end subroutine
247247

248-
! CHECK-LABEL: func.func @_QPdo_loop_with_goto
249-
subroutine do_loop_with_goto()
250-
integer :: i
251-
integer, parameter :: n = 10
252-
real, dimension(n) :: a, b
253-
254-
! Do loop with goto - unstructured control flow is not converted.
255-
!$acc kernels
256-
do i = 1, n
257-
a(i) = b(i) + 1.0
258-
if (i == 5) goto 100
259-
100 continue
260-
end do
261-
!$acc end kernels
262-
263-
! CHECK: acc.kernels {
264-
! CHECK-NOT: acc.loop
265-
266-
end subroutine
267-
268-
269-
! CHECK-LABEL: func.func @_QPdo_loop_with_cycle_goto
270-
subroutine do_loop_with_cycle_goto()
271-
integer :: i
272-
integer, parameter :: n = 10
273-
real, dimension(n) :: a, b
274-
275-
! Do loop with cycle and goto - unstructured control flow is not converted.
276-
!$acc kernels
277-
do i = 1, n
278-
if (i == 3) cycle
279-
a(i) = b(i) + 1.0
280-
if (i == 7) goto 200
281-
a(i) = a(i) * 2.0
282-
end do
283-
200 continue
284-
!$acc end kernels
285-
286-
! CHECK: acc.kernels {
287-
! CHECK-NOT: acc.loop
288-
289-
end subroutine
290-
291-
! CHECK-LABEL: func.func @_QPnested_goto_loop
292-
subroutine nested_goto_loop()
293-
integer :: i, j
294-
integer, parameter :: n = 10, m = 5
295-
real, dimension(n,m) :: a, b
296-
297-
! Nested loop with goto from inner to outer - should NOT convert to acc.loop
298-
!$acc kernels
299-
do i = 1, n
300-
do j = 1, m
301-
a(i,j) = b(i,j) + 1.0
302-
if (i * j > 20) goto 300 ! Exit both loops
303-
end do
304-
end do
305-
300 continue
306-
!$acc end kernels
307-
308-
! CHECK: acc.kernels {
309-
! CHECK-NOT: acc.loop
310-
311-
end subroutine
312-
313248
! CHECK-LABEL: func.func @_QPwhile_like_loop
314249
subroutine while_like_loop()
315250
integer :: i

0 commit comments

Comments
 (0)