Skip to content

Commit b171849

Browse files
authored
[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt (#66325)
This follow an update made on OpenMP https://reviews.llvm.org/D129969 and was not possible on OpenACC until the unstructured construct was supported.
1 parent 6ebbb1f commit b171849

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

flang/include/flang/Lower/OpenACC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ void attachDeclarePreDeallocAction(AbstractConverter &, fir::FirOpBuilder &,
103103
void attachDeclarePostDeallocAction(AbstractConverter &, fir::FirOpBuilder &,
104104
const Fortran::semantics::Symbol &);
105105

106+
void genOpenACCTerminator(fir::FirOpBuilder &, mlir::Operation *,
107+
mlir::Location);
108+
106109
} // namespace lower
107110
} // namespace Fortran
108111

flang/lib/Lower/OpenACC.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,3 +3299,12 @@ void Fortran::lower::attachDeclarePostDeallocAction(
32993299
/*preAlloc=*/{}, /*postAlloc=*/{}, /*preDealloc=*/{},
33003300
/*postDealloc=*/builder.getSymbolRefAttr(fctName.str())));
33013301
}
3302+
3303+
void Fortran::lower::genOpenACCTerminator(fir::FirOpBuilder &builder,
3304+
mlir::Operation *op,
3305+
mlir::Location loc) {
3306+
if (mlir::isa<mlir::acc::ParallelOp, mlir::acc::LoopOp>(op))
3307+
builder.create<mlir::acc::YieldOp>(loc);
3308+
else
3309+
builder.create<mlir::acc::TerminatorOp>(loc);
3310+
}

flang/lib/Lower/Runtime.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "flang/Lower/Runtime.h"
1010
#include "flang/Lower/Bridge.h"
11+
#include "flang/Lower/OpenACC.h"
1112
#include "flang/Lower/OpenMP.h"
1213
#include "flang/Lower/StatementContext.h"
1314
#include "flang/Optimizer/Builder/FIRBuilder.h"
@@ -21,6 +22,7 @@
2122
#include "flang/Runtime/stop.h"
2223
#include "flang/Runtime/time-intrinsic.h"
2324
#include "flang/Semantics/tools.h"
25+
#include "mlir/Dialect/OpenACC/OpenACC.h"
2426
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
2527
#include "llvm/Support/Debug.h"
2628
#include <optional>
@@ -37,6 +39,9 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) {
3739
if (parentOp->getDialect()->getNamespace() ==
3840
mlir::omp::OpenMPDialect::getDialectNamespace())
3941
Fortran::lower::genOpenMPTerminator(builder, parentOp, loc);
42+
else if (parentOp->getDialect()->getNamespace() ==
43+
mlir::acc::OpenACCDialect::getDialectNamespace())
44+
Fortran::lower::genOpenACCTerminator(builder, parentOp, loc);
4045
else
4146
builder.create<fir::UnreachableOp>(loc);
4247
mlir::Block *newBlock = curBlock->splitBlock(builder.getInsertionPoint());

flang/test/Lower/OpenACC/acc-unstructured.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ subroutine test_unstructured2(a, b, c)
5757
! CHECK: acc.parallel
5858
! CHECK: acc.loop
5959
! CHECK: fir.call @_FortranAStopStatementText
60-
! CHECK: fir.unreachable
60+
! CHECK: acc.yield
6161
! CHECK: acc.yield
6262
! CHECK: acc.yield
6363

@@ -80,7 +80,7 @@ subroutine test_unstructured3(a, b, c)
8080
! CHECK-LABEL: func.func @_QPtest_unstructured3
8181
! CHECK: acc.parallel
8282
! CHECK: fir.call @_FortranAStopStatementText
83-
! CHECK: fir.unreachable
83+
! CHECK: acc.yield
8484
! CHECK: acc.yield
8585

8686
end subroutine

flang/test/Lower/OpenACC/stop-stmt-in-region.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ subroutine test_stop_in_region1()
2929
! CHECK: %[[VAL_2:.*]] = arith.constant false
3030
! CHECK: %[[VAL_3:.*]] = arith.constant false
3131
! CHECK: %[[VAL_4:.*]] = fir.call @_FortranAStopStatement(%[[VAL_1]], %[[VAL_2]], %[[VAL_3]]) {{.*}} : (i32, i1, i1) -> none
32-
! CHECK: fir.unreachable
32+
! CHECK: acc.yield
3333
! CHECK: }
3434
! CHECK: return
3535
! CHECK: }

0 commit comments

Comments
 (0)