Skip to content

Commit f80c05c

Browse files
authored
[flang][openacc] Only generate acc.terminator in compute construct (#155504)
When the end of a block is inside a data region (not a compute region), generating an `acc.terminator` will lead to a missing terminator when translating to LLVM. Only generate acc.terminator instead of fir.unreachable when nested in acc compute region.
1 parent aadc708 commit f80c05c

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

flang/lib/Lower/Runtime.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) {
3939
if (parentOp->getDialect()->getNamespace() ==
4040
mlir::omp::OpenMPDialect::getDialectNamespace())
4141
Fortran::lower::genOpenMPTerminator(builder, parentOp, loc);
42-
else if (parentOp->getDialect()->getNamespace() ==
43-
mlir::acc::OpenACCDialect::getDialectNamespace())
42+
else if (Fortran::lower::isInsideOpenACCComputeConstruct(builder))
4443
Fortran::lower::genOpenACCTerminator(builder, parentOp, loc);
4544
else
4645
fir::UnreachableOp::create(builder, loc);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
! Check that acc.terminator is not inserted in data construct
2+
3+
! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
4+
5+
program main
6+
use, intrinsic :: iso_c_binding
7+
implicit none
8+
9+
real(8), pointer :: a(:,:,:),b(:,:,:),c(:,:,:),c2(:,:,:)
10+
integer, parameter :: n1 = 400, n2 = 20
11+
integer*4 :: stat
12+
integer :: i,j,k
13+
14+
stat = 0
15+
do i=1,n2
16+
17+
!$acc data copyin(a(:,:,i),b(:,:,i),c(:,:,i)) copyout(c2(:,:,i))
18+
19+
!$acc host_data use_device(a(:,:,i),b(:,:,i),c(:,:,i))
20+
21+
!$acc end host_data
22+
23+
if ( stat .ne. 0 ) then
24+
print *, "stat = ",stat
25+
stop ! terminator here should be fir.unreachable
26+
end if
27+
28+
!$acc parallel loop present(c(:,:,i),c2(:,:,i))
29+
do j = 1,n1
30+
do k = 1,n1
31+
c2(k,j,i) = 1.5d0 * c(k,j,i)
32+
enddo
33+
enddo
34+
!$acc end parallel loop
35+
36+
!$acc end data
37+
38+
enddo
39+
40+
!$acc wait
41+
42+
deallocate(a,b,c,c2)
43+
end program
44+
45+
! CHECK-LABEL: func.func @_QQmain()
46+
! CHECK: acc.data
47+
! CHECK: acc.host_data
48+
! CHECK: acc.terminator
49+
! CHECK: fir.call @_FortranAStopStatement
50+
! CHECK: fir.unreachable
51+
! CHECK: acc.parallel
52+
! CHECK-COUNT-3: acc.yield
53+
! CHECK: acc.terminator

0 commit comments

Comments
 (0)