[llvm] 36e24da - [flang][openacc][NFC] Make self clause value optional in ACC.td and extract the parser

Valentin Clement via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 06:45:24 PDT 2022


Author: Valentin Clement
Date: 2022-07-08T15:45:12+02:00
New Revision: 36e24da8eb56f8e68e2874305d3ea0e59d37f7b8

URL: https://github.com/llvm/llvm-project/commit/36e24da8eb56f8e68e2874305d3ea0e59d37f7b8
DIFF: https://github.com/llvm/llvm-project/commit/36e24da8eb56f8e68e2874305d3ea0e59d37f7b8.diff

LOG: [flang][openacc][NFC] Make self clause value optional in ACC.td and extract the parser

Set the isOptional flag for the self clause. Move the optional and parenthesis part of the parser. Update the rest of the code to deal with the optional value.

Preparatory work for D106968.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D106965

Added: 
    

Modified: 
    flang/lib/Lower/OpenACC.cpp
    flang/lib/Parser/openacc-parsers.cpp
    flang/lib/Semantics/check-acc-structure.cpp
    llvm/include/llvm/Frontend/OpenACC/ACC.td

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 6172cac852a95..0eec586ab02a3 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -407,33 +407,36 @@ createParallelOp(Fortran::lower::AbstractConverter &converter,
       genIfClause(converter, ifClause, ifCond, stmtCtx);
     } else if (const auto *selfClause =
                    std::get_if<Fortran::parser::AccClause::Self>(&clause.u)) {
-      const Fortran::parser::AccSelfClause &accSelfClause = selfClause->v;
-      if (const auto *optCondition =
-              std::get_if<std::optional<Fortran::parser::ScalarLogicalExpr>>(
-                  &accSelfClause.u)) {
-        if (*optCondition) {
-          mlir::Value cond = fir::getBase(converter.genExprValue(
-              *Fortran::semantics::GetExpr(*optCondition), stmtCtx));
-          selfCond = firOpBuilder.createConvert(currentLocation,
-                                                firOpBuilder.getI1Type(), cond);
-        } else {
-          addSelfAttr = true;
-        }
-      } else if (const auto *accClauseList =
-                     std::get_if<Fortran::parser::AccObjectList>(
-                         &accSelfClause.u)) {
-        // TODO This would be nicer to be done in canonicalization step.
-        if (accClauseList->v.size() == 1) {
-          const auto &accObject = accClauseList->v.front();
-          if (const auto *designator =
-                  std::get_if<Fortran::parser::Designator>(&accObject.u)) {
-            if (const auto *name = getDesignatorNameIfDataRef(*designator)) {
-              auto cond = converter.getSymbolAddress(*name->symbol);
-              selfCond = firOpBuilder.createConvert(
-                  currentLocation, firOpBuilder.getI1Type(), cond);
+      const std::optional<Fortran::parser::AccSelfClause> &accSelfClause =
+          selfClause->v;
+      if (accSelfClause) {
+        if (const auto *optCondition =
+                std::get_if<std::optional<Fortran::parser::ScalarLogicalExpr>>(
+                    &(*accSelfClause).u)) {
+          if (*optCondition) {
+            mlir::Value cond = fir::getBase(converter.genExprValue(
+                *Fortran::semantics::GetExpr(*optCondition), stmtCtx));
+            selfCond = firOpBuilder.createConvert(
+                currentLocation, firOpBuilder.getI1Type(), cond);
+          }
+        } else if (const auto *accClauseList =
+                       std::get_if<Fortran::parser::AccObjectList>(
+                           &(*accSelfClause).u)) {
+          // TODO This would be nicer to be done in canonicalization step.
+          if (accClauseList->v.size() == 1) {
+            const auto &accObject = accClauseList->v.front();
+            if (const auto *designator =
+                    std::get_if<Fortran::parser::Designator>(&accObject.u)) {
+              if (const auto *name = getDesignatorNameIfDataRef(*designator)) {
+                auto cond = converter.getSymbolAddress(*name->symbol);
+                selfCond = firOpBuilder.createConvert(
+                    currentLocation, firOpBuilder.getI1Type(), cond);
+              }
             }
           }
         }
+      } else {
+        addSelfAttr = true;
       }
     } else if (const auto *copyClause =
                    std::get_if<Fortran::parser::AccClause::Copy>(&clause.u)) {

diff  --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index 26cacc9135c8b..61b2b238aa89b 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -98,8 +98,8 @@ TYPE_PARSER("AUTO" >> construct<AccClause>(construct<AccClause::Auto>()) ||
                        parenthesized(construct<AccObjectListWithReduction>(
                            Parser<AccReductionOperator>{} / ":",
                            Parser<AccObjectList>{})))) ||
-    "SELF" >> construct<AccClause>(
-                  construct<AccClause::Self>(Parser<AccSelfClause>{})) ||
+    "SELF" >> construct<AccClause>(construct<AccClause::Self>(
+                  maybe(parenthesized(Parser<AccSelfClause>{})))) ||
     "SEQ" >> construct<AccClause>(construct<AccClause::Seq>()) ||
     "TILE" >> construct<AccClause>(construct<AccClause::Tile>(
                   parenthesized(Parser<AccTileExprList>{}))) ||
@@ -178,8 +178,8 @@ TYPE_PARSER(construct<AccDefaultClause>(parenthesized(
 // SELF clause is either a simple optional condition for compute construct
 // or a synonym of the HOST clause for the update directive 2.14.4 holding
 // an object list.
-TYPE_PARSER(construct<AccSelfClause>(parenthesized(Parser<AccObjectList>{})) ||
-    construct<AccSelfClause>(maybe(parenthesized(scalarLogicalExpr))))
+TYPE_PARSER(construct<AccSelfClause>(Parser<AccObjectList>{}) ||
+    construct<AccSelfClause>(scalarLogicalExpr))
 
 // Modifier for copyin, copyout, cache and create
 TYPE_PARSER(construct<AccDataModifier>(

diff  --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 2cb1059a57b35..58cbc33d5dcb8 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -409,17 +409,20 @@ void AccStructureChecker::Enter(const parser::AccClause::Copyout &c) {
 
 void AccStructureChecker::Enter(const parser::AccClause::Self &x) {
   CheckAllowed(llvm::acc::Clause::ACCC_self);
-  const parser::AccSelfClause &accSelfClause = x.v;
+  const std::optional<parser::AccSelfClause> &accSelfClause = x.v;
   if (GetContext().directive == llvm::acc::Directive::ACCD_update &&
-      std::holds_alternative<std::optional<parser::ScalarLogicalExpr>>(
-          accSelfClause.u)) {
+      ((accSelfClause &&
+           std::holds_alternative<std::optional<parser::ScalarLogicalExpr>>(
+               (*accSelfClause).u)) ||
+          !accSelfClause)) {
     context_.Say(GetContext().clauseSource,
         "SELF clause on the %s directive must have a var-list"_err_en_US,
         ContextDirectiveAsFortran());
   } else if (GetContext().directive != llvm::acc::Directive::ACCD_update &&
-      std::holds_alternative<parser::AccObjectList>(accSelfClause.u)) {
+      accSelfClause &&
+      std::holds_alternative<parser::AccObjectList>((*accSelfClause).u)) {
     const auto &accObjectList =
-        std::get<parser::AccObjectList>(accSelfClause.u);
+        std::get<parser::AccObjectList>((*accSelfClause).u);
     if (accObjectList.v.size() != 1) {
       context_.Say(GetContext().clauseSource,
           "SELF clause on the %s directive only accepts optional scalar logical"

diff  --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index c68330665b029..10c282b0217dc 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -218,6 +218,7 @@ def ACCC_Reduction : Clause<"reduction"> {
 // 2.5.6
 def ACCC_Self : Clause<"self"> {
   let flangClass = "AccSelfClause";
+  let isValueOptional = true;
 }
 
 // 2.9.5


        


More information about the llvm-commits mailing list