[llvm] 015834e - [flang][openacc][NFC] Extract device_type parser to its own

Valentin Clement via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 07:02:09 PDT 2022


Author: Valentin Clement
Date: 2022-07-08T16:02:04+02:00
New Revision: 015834e45581e91deb310d508c38a5e36a220c0d

URL: https://github.com/llvm/llvm-project/commit/015834e45581e91deb310d508c38a5e36a220c0d
DIFF: https://github.com/llvm/llvm-project/commit/015834e45581e91deb310d508c38a5e36a220c0d.diff

LOG: [flang][openacc][NFC] Extract device_type parser to its own

Move the device_type parser to a separate parser AccDeviceTypeExprList. Preparatory work for D106968.

Reviewed By: kiranchandramohan

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

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
    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 a81125e19e6dc..c97c368a847da 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -92,6 +92,8 @@ class ParseTreeDumper {
   NODE(parser, AccSizeExprList)
   NODE(parser, AccSelfClause)
   NODE(parser, AccStandaloneDirective)
+  NODE(parser, AccDeviceTypeExpr)
+  NODE(parser, AccDeviceTypeExprList)
   NODE(parser, AccTileExpr)
   NODE(parser, AccTileExprList)
   NODE(parser, AccLoopDirective)

diff  --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index e1521f00ff0f8..0c16844749056 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3915,6 +3915,17 @@ struct AccWaitArgument {
   std::tuple<std::optional<ScalarIntExpr>, std::list<ScalarIntExpr>> t;
 };
 
+struct AccDeviceTypeExpr {
+  TUPLE_CLASS_BOILERPLATE(AccDeviceTypeExpr);
+  CharBlock source;
+  std::tuple<std::optional<ScalarIntExpr>> t; // if null then *
+};
+
+struct AccDeviceTypeExprList {
+  WRAPPER_CLASS_BOILERPLATE(
+      AccDeviceTypeExprList, std::list<AccDeviceTypeExpr>);
+};
+
 struct AccTileExpr {
   TUPLE_CLASS_BOILERPLATE(AccTileExpr);
   CharBlock source;

diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 0eec586ab02a3..e04ced0e548bc 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -151,19 +151,21 @@ static void genDeviceTypeClause(
     const Fortran::parser::AccClause::DeviceType *deviceTypeClause,
     llvm::SmallVectorImpl<mlir::Value> &operands,
     Fortran::lower::StatementContext &stmtCtx) {
-  const auto &deviceTypeValue = deviceTypeClause->v;
-  if (deviceTypeValue) {
-    for (const auto &scalarIntExpr : *deviceTypeValue) {
-      mlir::Value expr = fir::getBase(converter.genExprValue(
-          *Fortran::semantics::GetExpr(scalarIntExpr), stmtCtx));
-      operands.push_back(expr);
+  const Fortran::parser::AccDeviceTypeExprList &deviceTypeExprList =
+      deviceTypeClause->v;
+  for (const auto &deviceTypeExpr : deviceTypeExprList.v) {
+    const auto &expr = std::get<std::optional<Fortran::parser::ScalarIntExpr>>(
+        deviceTypeExpr.t);
+    if (expr) {
+      operands.push_back(fir::getBase(
+          converter.genExprValue(*Fortran::semantics::GetExpr(expr), stmtCtx)));
+    } else {
+      // * was passed as value and will be represented as a special constant.
+      fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+      mlir::Value star = firOpBuilder.createIntegerConstant(
+          converter.getCurrentLocation(), firOpBuilder.getIndexType(), starCst);
+      operands.push_back(star);
     }
-  } else {
-    fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
-    // * was passed as value and will be represented as a special constant.
-    mlir::Value star = firOpBuilder.createIntegerConstant(
-        converter.getCurrentLocation(), firOpBuilder.getIndexType(), starCst);
-    operands.push_back(star);
   }
 }
 

diff  --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index 61b2b238aa89b..f11f6530951a3 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -62,12 +62,9 @@ TYPE_PARSER("AUTO" >> construct<AccClause>(construct<AccClause::Auto>()) ||
     "DEVICE_RESIDENT" >>
         construct<AccClause>(construct<AccClause::DeviceResident>(
             parenthesized(Parser<AccObjectList>{}))) ||
-    ("DEVICE_TYPE"_tok || "DTYPE"_tok) >>
-        construct<AccClause>(construct<AccClause::DeviceType>(parenthesized(
-            "*" >> construct<std::optional<std::list<ScalarIntExpr>>>()))) ||
     ("DEVICE_TYPE"_tok || "DTYPE"_tok) >>
         construct<AccClause>(construct<AccClause::DeviceType>(
-            parenthesized(maybe(nonemptyList(scalarIntExpr))))) ||
+            parenthesized(Parser<AccDeviceTypeExprList>{}))) ||
     "FINALIZE" >> construct<AccClause>(construct<AccClause::Finalize>()) ||
     "FIRSTPRIVATE" >> construct<AccClause>(construct<AccClause::Firstprivate>(
                           parenthesized(Parser<AccObjectList>{}))) ||
@@ -137,6 +134,12 @@ TYPE_PARSER(construct<AccSizeExpr>(scalarIntExpr) ||
     construct<AccSizeExpr>("*" >> construct<std::optional<ScalarIntExpr>>()))
 TYPE_PARSER(construct<AccSizeExprList>(nonemptyList(Parser<AccSizeExpr>{})))
 
+TYPE_PARSER(construct<AccDeviceTypeExpr>(scalarIntExpr) ||
+    construct<AccDeviceTypeExpr>(
+        "*" >> construct<std::optional<ScalarIntExpr>>()))
+TYPE_PARSER(
+    construct<AccDeviceTypeExprList>(nonemptyList(Parser<AccDeviceTypeExpr>{})))
+
 // tile size is one of:
 //   * (represented as an empty std::optional<ScalarIntExpr>)
 //   constant-int-expr

diff  --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index 10c282b0217dc..45d8158944549 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -128,10 +128,8 @@ def ACCC_DeviceResident : Clause<"device_resident"> {
 
 // 2.4
 def ACCC_DeviceType : Clause<"device_type"> {
-  let flangClass = "ScalarIntExpr";
+  let flangClass = "AccDeviceTypeExprList";
   let defaultValue = "*";
-  let isValueOptional = true;
-  let isValueList = true;
 }
 
 // 2.6.6


        


More information about the llvm-commits mailing list