[flang-commits] [flang] ba2082c - [flang][openacc] Lower the entry part for OpenACC declare in function/subroutine
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Aug 1 14:04:36 PDT 2023
Author: Valentin Clement
Date: 2023-08-01T14:04:30-07:00
New Revision: ba2082cdffcfb83715d3f03ee679c583c70e39d4
URL: https://github.com/llvm/llvm-project/commit/ba2082cdffcfb83715d3f03ee679c583c70e39d4
DIFF: https://github.com/llvm/llvm-project/commit/ba2082cdffcfb83715d3f03ee679c583c70e39d4.diff
LOG: [flang][openacc] Lower the entry part for OpenACC declare in function/subroutine
This patch adds lowering for the entry part of the OpenACC declare construct
in function/subroutine. The exit part will come as a follow up patch.
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D156560
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 50ea53bea87a3d..e59478556544a5 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -372,6 +372,14 @@ static Op createDataEntryOp(fir::FirOpBuilder &builder, mlir::Location loc,
return op;
}
+static void addDeclareAttr(fir::FirOpBuilder &builder, mlir::Operation *op,
+ mlir::acc::DataClause clause) {
+ op->setAttr(mlir::acc::getDeclareAttrName(),
+ mlir::acc::DeclareAttr::get(builder.getContext(),
+ mlir::acc::DataClauseAttr::get(
+ builder.getContext(), clause)));
+}
+
template <typename Op>
static void
genDataOperandOperations(const Fortran::parser::AccObjectList &objectList,
@@ -379,7 +387,8 @@ genDataOperandOperations(const Fortran::parser::AccObjectList &objectList,
Fortran::semantics::SemanticsContext &semanticsContext,
Fortran::lower::StatementContext &stmtCtx,
llvm::SmallVectorImpl<mlir::Value> &dataOperands,
- mlir::acc::DataClause dataClause, bool structured) {
+ mlir::acc::DataClause dataClause, bool structured,
+ bool setDeclareAttr = false) {
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
for (const auto &accObject : objectList.v) {
llvm::SmallVector<mlir::Value> bounds;
@@ -392,6 +401,8 @@ genDataOperandOperations(const Fortran::parser::AccObjectList &objectList,
bounds, structured, dataClause,
baseAddr.getType());
dataOperands.push_back(op.getAccPtr());
+ if (setDeclareAttr)
+ addDeclareAttr(builder, op.getVarPtr().getDefiningOp(), dataClause);
}
}
@@ -2283,14 +2294,6 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
waitOp.setAsyncAttr(firOpBuilder.getUnitAttr());
}
-static void addDeclareAttr(fir::FirOpBuilder &builder, mlir::Operation *op,
- mlir::acc::DataClause clause) {
- op->setAttr(mlir::acc::getDeclareAttrName(),
- mlir::acc::DeclareAttr::get(builder.getContext(),
- mlir::acc::DataClauseAttr::get(
- builder.getContext(), clause)));
-}
-
template <typename GlobalOp, typename EntryOp, typename DeclareOp,
typename ExitOp>
static void createDeclareGlobalOp(mlir::OpBuilder &modBuilder,
@@ -2391,6 +2394,34 @@ genGlobalCtorsWithModifier(Fortran::lower::AbstractConverter &converter,
dataClause);
}
+static void
+genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semanticsContext,
+ mlir::Location loc,
+ const Fortran::parser::AccClauseList &accClauseList) {
+ llvm::SmallVector<mlir::Value> dataClauseOperands, copyEntryOperands;
+ Fortran::lower::StatementContext stmtCtx;
+ fir::FirOpBuilder &builder = converter.getFirOpBuilder();
+ for (const Fortran::parser::AccClause &clause : accClauseList.v) {
+ if (const auto *copyClause =
+ std::get_if<Fortran::parser::AccClause::Copy>(&clause.u)) {
+ auto crtDataStart = dataClauseOperands.size();
+
+ genDataOperandOperations<mlir::acc::CopyinOp>(
+ copyClause->v, converter, semanticsContext, stmtCtx,
+ dataClauseOperands, mlir::acc::DataClause::acc_copy,
+ /*structured=*/true, /*setDeclareAttr=*/true);
+ copyEntryOperands.append(dataClauseOperands.begin() + crtDataStart,
+ dataClauseOperands.end());
+ } else {
+ mlir::Location clauseLocation = converter.genLocation(clause.source);
+ TODO(clauseLocation, "clause on declare directive");
+ }
+ }
+
+ builder.create<mlir::acc::DeclareEnterOp>(loc, dataClauseOperands);
+}
+
static void
genDeclareInModule(Fortran::lower::AbstractConverter &converter,
mlir::ModuleOp &moduleOp,
@@ -2440,6 +2471,8 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
const auto &declarativeDir =
std::get<Fortran::parser::AccDeclarativeDirective>(declareConstruct.t);
+ mlir::Location directiveLocation =
+ converter.genLocation(declarativeDir.source);
const auto &accClauseList =
std::get<Fortran::parser::AccClauseList>(declareConstruct.t);
@@ -2450,7 +2483,8 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
auto funcOp =
builder.getBlock()->getParent()->getParentOfType<mlir::func::FuncOp>();
if (funcOp)
- TODO(funcOp.getLoc(), "OpenACC declare in function/subroutine");
+ genDeclareInFunction(converter, semanticsContext, directiveLocation,
+ accClauseList);
else if (moduleOp)
genDeclareInModule(converter, moduleOp, accClauseList);
return;
diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index d5b0a48d7a90a9..237da9e264267e 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -68,3 +68,23 @@ module acc_declare_device_link_test
! CHECK: acc.declare_enter dataOperands(%[[LINK]] : !fir.ref<!fir.array<5000xi32>>)
! CHECK: acc.terminator
! CHECK: }
+
+module acc_declare
+ contains
+
+ subroutine acc_declare_copy()
+ integer :: a(100), i
+ !$acc declare copy(a)
+
+ do i = 1, 100
+ a(i) = i
+ end do
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_copy()
+! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32> {acc.declare = #acc.declare<dataClause = acc_copy>, bindc_name = "a", uniq_name = "_QMacc_declareFacc_declare_copyEa"}
+! CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%c1 : index) startIdx(%c1 : index)
+! CHECK: %[[COPYIN:.*]] = acc.copyin varPtr(%[[ALLOCA]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xi32>> {dataClause = #acc<data_clause acc_copy>, name = "a"}
+! CHECK: acc.declare_enter dataOperands(%[[COPYIN]] : !fir.ref<!fir.array<100xi32>>)
+
+end module
More information about the flang-commits
mailing list