[flang-commits] [flang] ae86fe8 - [flang][openacc] Add parser support for the force modifier in the collapse clause
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Mon Jun 12 11:02:07 PDT 2023
Author: Valentin Clement
Date: 2023-06-12T11:01:59-07:00
New Revision: ae86fe859170cfd0befcaa1fc7a6cae80a370cbf
URL: https://github.com/llvm/llvm-project/commit/ae86fe859170cfd0befcaa1fc7a6cae80a370cbf
DIFF: https://github.com/llvm/llvm-project/commit/ae86fe859170cfd0befcaa1fc7a6cae80a370cbf.diff
LOG: [flang][openacc] Add parser support for the force modifier in the collapse clause
This patch adds parser support for the force modifier on the collapse clause
introduced in OpenACC 3.3.
Lowering will currently hit a TODO as the MLIR representation of the acc.loop
might need some update.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D151974
Added:
Modified:
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Lower/OpenACC.cpp
flang/lib/Parser/openacc-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/check-acc-structure.cpp
flang/lib/Semantics/resolve-directives.cpp
flang/test/Parser/acc-unparse.f90
llvm/include/llvm/Frontend/OpenACC/ACC.td
Removed:
################################################################################
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 158064c2f3e31..11d3bb8ef1f3c 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -85,6 +85,7 @@ class ParseTreeDumper {
NODE(parser, AccEndBlockDirective)
NODE(parser, AccEndCombinedDirective)
NODE(parser, AccGangArgument)
+ NODE(parser, AccCollapseArg)
NODE(parser, AccObject)
NODE(parser, AccObjectList)
NODE(parser, AccObjectListWithModifier)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 2742bb0fbc09e..0e8159b455dc5 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -4097,6 +4097,11 @@ struct AccGangArgument {
std::tuple<std::optional<ScalarIntExpr>, std::optional<AccSizeExpr>> t;
};
+struct AccCollapseArg {
+ TUPLE_CLASS_BOILERPLATE(AccCollapseArg);
+ std::tuple<bool, ScalarIntConstantExpr> t;
+};
+
struct AccClause {
UNION_CLASS_BOILERPLATE(AccClause);
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index abdf320cdfd98..9126b3cdea9ba 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -910,9 +910,16 @@ createLoopOp(Fortran::lower::AbstractConverter &converter,
// Lower clauses mapped to attributes
for (const Fortran::parser::AccClause &clause : accClauseList.v) {
+ mlir::Location clauseLocation = converter.genLocation(clause.source);
if (const auto *collapseClause =
std::get_if<Fortran::parser::AccClause::Collapse>(&clause.u)) {
- const auto *expr = Fortran::semantics::GetExpr(collapseClause->v);
+ const Fortran::parser::AccCollapseArg &arg = collapseClause->v;
+ const auto &force = std::get<bool>(arg.t);
+ if (force)
+ TODO(clauseLocation, "OpenACC collapse force modifier");
+ const auto &intExpr =
+ std::get<Fortran::parser::ScalarIntConstantExpr>(arg.t);
+ const auto *expr = Fortran::semantics::GetExpr(intExpr);
const std::optional<int64_t> collapseValue =
Fortran::evaluate::ToInt64(*expr);
if (collapseValue) {
diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index fa5e41562d409..3ea5b78b980de 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -72,6 +72,10 @@ TYPE_PARSER(construct<AccGangArgument>(
maybe(("NUM:"_tok >> scalarIntExpr || scalarIntExpr)),
maybe(", STATIC:" >> Parser<AccSizeExpr>{})))
+// 2.9.1 collapse
+TYPE_PARSER(construct<AccCollapseArg>(
+ "FORCE:"_tok >> pure(true) || pure(false), scalarIntConstantExpr))
+
// 2.5.13 Reduction
// Operator for reduction
TYPE_PARSER(sourced(construct<AccReductionOperator>(
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index ff716236b77e6..94bd34e8e6d0b 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -1912,6 +1912,14 @@ class UnparseVisitor {
Walk("NUM:", std::get<std::optional<ScalarIntExpr>>(x.t));
Walk(", STATIC:", std::get<std::optional<AccSizeExpr>>(x.t));
}
+ void Unparse(const AccCollapseArg &x) {
+ const auto &force{std::get<bool>(x.t)};
+ const auto &collapseValue{std::get<parser::ScalarIntConstantExpr>(x.t)};
+ if (force) {
+ Put("FORCE:");
+ }
+ Walk(collapseValue);
+ }
void Unparse(const OpenACCBlockConstruct &x) {
BeginOpenACC();
Word("!$ACC ");
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 58cbc33d5dcb8..fd96aa588d3f6 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -307,8 +307,6 @@ void AccStructureChecker::Leave(const parser::OpenACCCacheConstruct &x) {
}
// Clause checkers
-CHECK_REQ_SCALAR_INT_CONSTANT_CLAUSE(Collapse, ACCC_collapse)
-
CHECK_SIMPLE_CLAUSE(Auto, ACCC_auto)
CHECK_SIMPLE_CLAUSE(Async, ACCC_async)
CHECK_SIMPLE_CLAUSE(Attach, ACCC_attach)
@@ -432,6 +430,15 @@ void AccStructureChecker::Enter(const parser::AccClause::Self &x) {
}
}
+void AccStructureChecker::Enter(const parser::AccClause::Collapse &x) {
+ CheckAllowed(llvm::acc::Clause::ACCC_collapse);
+ const parser::AccCollapseArg &accCollapseArg = x.v;
+ const auto &collapseValue{
+ std::get<parser::ScalarIntConstantExpr>(accCollapseArg.t)};
+ RequiresConstantPositiveParameter(
+ llvm::acc::Clause::ACCC_collapse, collapseValue);
+}
+
llvm::StringRef AccStructureChecker::getClauseName(llvm::acc::Clause clause) {
return llvm::acc::getOpenACCClauseName(clause);
}
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 73f451a9bd536..64ebb6c98df9a 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -904,7 +904,9 @@ std::int64_t AccAttributeVisitor::GetAssociatedLoopLevelFromClauses(
for (const auto &clause : x.v) {
if (const auto *collapseClause{
std::get_if<parser::AccClause::Collapse>(&clause.u)}) {
- if (const auto v{EvaluateInt64(context_, collapseClause->v)}) {
+ const parser::AccCollapseArg &arg = collapseClause->v;
+ const auto &collapseValue{std::get<parser::ScalarIntConstantExpr>(arg.t)};
+ if (const auto v{EvaluateInt64(context_, collapseValue)}) {
collapseLevel = *v;
}
}
diff --git a/flang/test/Parser/acc-unparse.f90 b/flang/test/Parser/acc-unparse.f90
index d4d48294d4a6e..088b6b8afdb30 100644
--- a/flang/test/Parser/acc-unparse.f90
+++ b/flang/test/Parser/acc-unparse.f90
@@ -17,3 +17,17 @@ program bug47659
!CHECK-LABEL: PROGRAM bug47659
!CHECK: !$ACC PARALLEL LOOP
+
+
+subroutine acc_loop()
+ integer :: i, j
+
+ !$acc loop collapse(force: 2)
+ do i = 1, 10
+ do j = 1, 10
+ end do
+ end do
+end subroutine
+
+!CHECK-LABEL: SUBROUTINE acc_loop
+!CHECK: !$ACC LOOP COLLAPSE(FORCE:2_4)
diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index b9e468af667ad..374230e34f623 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -56,7 +56,7 @@ def ACCC_Capture : Clause<"capture"> {
// 2.9.1
def ACCC_Collapse : Clause<"collapse"> {
- let flangClass = "ScalarIntConstantExpr";
+ let flangClass = "AccCollapseArg";
}
// 2.7.6
More information about the flang-commits
mailing list