Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt #66325

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flang/include/flang/Lower/OpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ void attachDeclarePreDeallocAction(AbstractConverter &, fir::FirOpBuilder &,
void attachDeclarePostDeallocAction(AbstractConverter &, fir::FirOpBuilder &,
const Fortran::semantics::Symbol &);

void genOpenACCTerminator(fir::FirOpBuilder &, mlir::Operation *,
mlir::Location);

} // namespace lower
} // namespace Fortran

Expand Down
9 changes: 9 additions & 0 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3299,3 +3299,12 @@ void Fortran::lower::attachDeclarePostDeallocAction(
/*preAlloc=*/{}, /*postAlloc=*/{}, /*preDealloc=*/{},
/*postDealloc=*/builder.getSymbolRefAttr(fctName.str())));
}

void Fortran::lower::genOpenACCTerminator(fir::FirOpBuilder &builder,
mlir::Operation *op,
mlir::Location loc) {
if (mlir::isa<mlir::acc::ParallelOp, mlir::acc::LoopOp>(op))
builder.create<mlir::acc::YieldOp>(loc);
else
builder.create<mlir::acc::TerminatorOp>(loc);
}
5 changes: 5 additions & 0 deletions flang/lib/Lower/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "flang/Lower/Runtime.h"
#include "flang/Lower/Bridge.h"
#include "flang/Lower/OpenACC.h"
#include "flang/Lower/OpenMP.h"
#include "flang/Lower/StatementContext.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
Expand All @@ -21,6 +22,7 @@
#include "flang/Runtime/stop.h"
#include "flang/Runtime/time-intrinsic.h"
#include "flang/Semantics/tools.h"
#include "mlir/Dialect/OpenACC/OpenACC.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "llvm/Support/Debug.h"
#include <optional>
Expand All @@ -37,6 +39,9 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) {
if (parentOp->getDialect()->getNamespace() ==
mlir::omp::OpenMPDialect::getDialectNamespace())
Fortran::lower::genOpenMPTerminator(builder, parentOp, loc);
else if (parentOp->getDialect()->getNamespace() ==
mlir::acc::OpenACCDialect::getDialectNamespace())
Fortran::lower::genOpenACCTerminator(builder, parentOp, loc);
else
builder.create<fir::UnreachableOp>(loc);
mlir::Block *newBlock = curBlock->splitBlock(builder.getInsertionPoint());
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Lower/OpenACC/acc-unstructured.f90
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ subroutine test_unstructured2(a, b, c)
! CHECK: acc.parallel
! CHECK: acc.loop
! CHECK: fir.call @_FortranAStopStatementText
! CHECK: fir.unreachable
! CHECK: acc.yield
! CHECK: acc.yield
! CHECK: acc.yield

Expand All @@ -80,7 +80,7 @@ subroutine test_unstructured3(a, b, c)
! CHECK-LABEL: func.func @_QPtest_unstructured3
! CHECK: acc.parallel
! CHECK: fir.call @_FortranAStopStatementText
! CHECK: fir.unreachable
! CHECK: acc.yield
! CHECK: acc.yield

end subroutine
2 changes: 1 addition & 1 deletion flang/test/Lower/OpenACC/stop-stmt-in-region.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ subroutine test_stop_in_region1()
! CHECK: %[[VAL_2:.*]] = arith.constant false
! CHECK: %[[VAL_3:.*]] = arith.constant false
! CHECK: %[[VAL_4:.*]] = fir.call @_FortranAStopStatement(%[[VAL_1]], %[[VAL_2]], %[[VAL_3]]) {{.*}} : (i32, i1, i1) -> none
! CHECK: fir.unreachable
! CHECK: acc.yield
! CHECK: }
! CHECK: return
! CHECK: }
Expand Down