Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorValentin Clement <clementval@gmail.com>2022-07-08 17:01:34 +0300
committerValentin Clement <clementval@gmail.com>2022-07-08 17:02:04 +0300
commit015834e45581e91deb310d508c38a5e36a220c0d (patch)
tree61474e20b40ba84dbcc5ec47ba633dce774aa3ba /flang
parent36e24da8eb56f8e68e2874305d3ea0e59d37f7b8 (diff)
[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
Diffstat (limited to 'flang')
-rw-r--r--flang/include/flang/Parser/dump-parse-tree.h2
-rw-r--r--flang/include/flang/Parser/parse-tree.h11
-rw-r--r--flang/lib/Lower/OpenACC.cpp26
-rw-r--r--flang/lib/Parser/openacc-parsers.cpp11
4 files changed, 34 insertions, 16 deletions
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index a81125e19e6d..c97c368a847d 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -92,6 +92,8 @@ public:
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 e1521f00ff0f..0c1684474905 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 0eec586ab02a..e04ced0e548b 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 61b2b238aa89..f11f6530951a 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -63,11 +63,8 @@ TYPE_PARSER("AUTO" >> construct<AccClause>(construct<AccClause::Auto>()) ||
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