[flang-commits] [flang] 34e53bf - [flang][openacc] Add lowering support for copyout clause on OpenACC declare
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Wed Aug 2 15:54:55 PDT 2023
Author: Valentin Clement
Date: 2023-08-02T15:54:49-07:00
New Revision: 34e53bf1cb30fe3731778227f8b93bd008ccefcc
URL: https://github.com/llvm/llvm-project/commit/34e53bf1cb30fe3731778227f8b93bd008ccefcc
DIFF: https://github.com/llvm/llvm-project/commit/34e53bf1cb30fe3731778227f8b93bd008ccefcc.diff
LOG: [flang][openacc] Add lowering support for copyout clause on OpenACC declare
Lower the copyout clause for the OpenACC declare directive
Depends on D156738
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D156824
Added:
Modified:
flang/lib/Lower/OpenACC.cpp
flang/test/Lower/OpenACC/acc-declare.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 692732a2a698aa..7ab6468320ee28 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2404,7 +2404,7 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
mlir::Location loc,
const Fortran::parser::AccClauseList &accClauseList) {
llvm::SmallVector<mlir::Value> dataClauseOperands, copyEntryOperands,
- createEntryOperands;
+ createEntryOperands, copyoutEntryOperands;
Fortran::lower::StatementContext stmtCtx;
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
for (const Fortran::parser::AccClause &clause : accClauseList.v) {
@@ -2444,6 +2444,20 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
Fortran::parser::AccDataModifier::Modifier::ReadOnly,
dataClauseOperands, mlir::acc::DataClause::acc_copyin,
mlir::acc::DataClause::acc_copyin_readonly, /*setDeclareAttr=*/true);
+ } else if (const auto *copyoutClause =
+ std::get_if<Fortran::parser::AccClause::Copyout>(
+ &clause.u)) {
+ const Fortran::parser::AccObjectListWithModifier &listWithModifier =
+ copyoutClause->v;
+ const auto &accObjectList =
+ std::get<Fortran::parser::AccObjectList>(listWithModifier.t);
+ auto crtDataStart = dataClauseOperands.size();
+ genDataOperandOperations<mlir::acc::CreateOp>(
+ accObjectList, converter, semanticsContext, stmtCtx,
+ dataClauseOperands, mlir::acc::DataClause::acc_copyout,
+ /*structured=*/true, /*setDeclareAttr=*/true);
+ copyoutEntryOperands.append(dataClauseOperands.begin() + crtDataStart,
+ dataClauseOperands.end());
} else {
mlir::Location clauseLocation = converter.genLocation(clause.source);
TODO(clauseLocation, "clause on declare directive");
@@ -2451,16 +2465,21 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
}
builder.create<mlir::acc::DeclareEnterOp>(loc, dataClauseOperands);
- if (!createEntryOperands.empty() || !copyEntryOperands.empty()) {
+ if (!createEntryOperands.empty() || !copyEntryOperands.empty() ||
+ !copyoutEntryOperands.empty()) {
// Attach declare exit operation generation to function context.
fctCtx.attachCleanup([&builder, loc, dataClauseOperands,
- createEntryOperands, copyEntryOperands]() {
+ createEntryOperands, copyEntryOperands,
+ copyoutEntryOperands]() {
builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
builder, createEntryOperands, /*structured=*/true,
/*implicit=*/false);
genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
+ genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
+ builder, copyoutEntryOperands, /*structured=*/true,
+ /*implicit=*/false);
});
}
}
diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index c0c7c4ee1c6066..971b0a14613e94 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -155,4 +155,22 @@ subroutine acc_declare_copyin()
! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
! CHECK-NOT: acc.declare_exit
+ subroutine acc_declare_copyout()
+ integer :: a(100), i
+ !$acc declare copyout(a)
+
+ do i = 1, 100
+ a(i) = i
+ end do
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_copyout()
+! CHECK: %[[A:.*]] = fir.alloca !fir.array<100xi32> {acc.declare = #acc.declare<dataClause = acc_copyout>, bindc_name = "a", uniq_name = "_QMacc_declareFacc_declare_copyoutEa"}
+! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[A]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<100xi32>> {dataClause = #acc<data_clause acc_copyout>, name = "a"}
+! CHECK: acc.declare_enter dataOperands(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>)
+! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
+! CHECK: acc.declare_exit dataOperands(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>)
+! CHECK: acc.copyout accPtr(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) to varPtr(%[[A]] : !fir.ref<!fir.array<100xi32>>) {name = "a"}
+! CHECK: return
+
end module
More information about the flang-commits
mailing list