[flang-commits] [flang] 8bc676c - [flang][openacc] Lower acc cache directive (#65673)
via flang-commits
flang-commits at lists.llvm.org
Mon Sep 11 13:38:26 PDT 2023
Author: Valentin Clement (バレンタイン クレメン)
Date: 2023-09-11T13:38:21-07:00
New Revision: 8bc676c2ec83f4664583f5b9b6c363d14a8a5a9e
URL: https://github.com/llvm/llvm-project/commit/8bc676c2ec83f4664583f5b9b6c363d14a8a5a9e
DIFF: https://github.com/llvm/llvm-project/commit/8bc676c2ec83f4664583f5b9b6c363d14a8a5a9e.diff
LOG: [flang][openacc] Lower acc cache directive (#65673)
The cache directive is attached directly to the acc.loop operation when
the directive appears in the loop. When it appears before a loop, the
OpenACCCacheConstruct is saved and attached when the acc.loop is
created.
Directive that cannot be attached to a loop are silently discarded.
Depends on #65521
Added:
Modified:
flang/lib/Lower/OpenACC.cpp
flang/test/Lower/OpenACC/acc-loop.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 5ead00ef89cbabc..a59a71ff8d8ae68 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -3096,6 +3096,41 @@ void Fortran::lower::finalizeOpenACCRoutineAttachment(
accRoutineInfos.clear();
}
+static void
+genACC(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semanticsContext,
+ const Fortran::parser::OpenACCCacheConstruct &cacheConstruct) {
+ fir::FirOpBuilder &builder = converter.getFirOpBuilder();
+ auto loopOp = builder.getRegion().getParentOfType<mlir::acc::LoopOp>();
+ auto crtPos = builder.saveInsertionPoint();
+ if (loopOp) {
+ builder.setInsertionPoint(loopOp);
+ Fortran::lower::StatementContext stmtCtx;
+ llvm::SmallVector<mlir::Value> cacheOperands;
+ const Fortran::parser::AccObjectListWithModifier &listWithModifier =
+ std::get<Fortran::parser::AccObjectListWithModifier>(cacheConstruct.t);
+ const auto &accObjectList =
+ std::get<Fortran::parser::AccObjectList>(listWithModifier.t);
+ const auto &modifier =
+ std::get<std::optional<Fortran::parser::AccDataModifier>>(
+ listWithModifier.t);
+
+ mlir::acc::DataClause dataClause = mlir::acc::DataClause::acc_cache;
+ if (modifier &&
+ (*modifier).v == Fortran::parser::AccDataModifier::Modifier::ReadOnly)
+ dataClause = mlir::acc::DataClause::acc_cache_readonly;
+ genDataOperandOperations<mlir::acc::CacheOp>(
+ accObjectList, converter, semanticsContext, stmtCtx, cacheOperands,
+ dataClause,
+ /*structured=*/true, /*implicit=*/false, /*setDeclareAttr*/ false);
+ loopOp.getCacheOperandsMutable().append(cacheOperands);
+ } else {
+ llvm::report_fatal_error(
+ "could not find loop to attach OpenACC cache information.");
+ }
+ builder.restoreInsertionPoint(crtPos);
+}
+
void Fortran::lower::genOpenACCConstruct(
Fortran::lower::AbstractConverter &converter,
Fortran::semantics::SemanticsContext &semanticsContext,
@@ -3119,8 +3154,7 @@ void Fortran::lower::genOpenACCConstruct(
genACC(converter, semanticsContext, standaloneConstruct);
},
[&](const Fortran::parser::OpenACCCacheConstruct &cacheConstruct) {
- TODO(converter.genLocation(cacheConstruct.source),
- "OpenACC Cache construct not lowered yet!");
+ genACC(converter, semanticsContext, cacheConstruct);
},
[&](const Fortran::parser::OpenACCWaitConstruct &waitConstruct) {
genACC(converter, waitConstruct);
diff --git a/flang/test/Lower/OpenACC/acc-loop.f90 b/flang/test/Lower/OpenACC/acc-loop.f90
index eac4fa41af82a31..17bcb6e509b41ef 100644
--- a/flang/test/Lower/OpenACC/acc-loop.f90
+++ b/flang/test/Lower/OpenACC/acc-loop.f90
@@ -305,4 +305,13 @@ program acc_loop
!CHECK: acc.yield
!CHECK-NEXT: }{{$}}
+ !$acc loop
+ DO i = 1, n
+ !$acc cache(b)
+ a(i) = b(i)
+ END DO
+
+! CHECK: %[[CACHE:.*]] = acc.cache varPtr(%{{.*}} : !fir.ref<!fir.array<10xf32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<10xf32>> {name = "b"}
+! CHECK: acc.loop cache(%[[CACHE]] : !fir.ref<!fir.array<10xf32>>)
+
end program
More information about the flang-commits
mailing list