[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
This commit is contained in:
Valentin Clement 2022-07-08 16:01:34 +02:00
parent 36e24da8eb
commit 015834e455
No known key found for this signature in database
GPG Key ID: 086D54783C928776
5 changed files with 35 additions and 19 deletions

View File

@ -92,6 +92,8 @@ public:
NODE(parser, AccSizeExprList) NODE(parser, AccSizeExprList)
NODE(parser, AccSelfClause) NODE(parser, AccSelfClause)
NODE(parser, AccStandaloneDirective) NODE(parser, AccStandaloneDirective)
NODE(parser, AccDeviceTypeExpr)
NODE(parser, AccDeviceTypeExprList)
NODE(parser, AccTileExpr) NODE(parser, AccTileExpr)
NODE(parser, AccTileExprList) NODE(parser, AccTileExprList)
NODE(parser, AccLoopDirective) NODE(parser, AccLoopDirective)

View File

@ -3915,6 +3915,17 @@ struct AccWaitArgument {
std::tuple<std::optional<ScalarIntExpr>, std::list<ScalarIntExpr>> t; 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 { struct AccTileExpr {
TUPLE_CLASS_BOILERPLATE(AccTileExpr); TUPLE_CLASS_BOILERPLATE(AccTileExpr);
CharBlock source; CharBlock source;

View File

@ -151,19 +151,21 @@ static void genDeviceTypeClause(
const Fortran::parser::AccClause::DeviceType *deviceTypeClause, const Fortran::parser::AccClause::DeviceType *deviceTypeClause,
llvm::SmallVectorImpl<mlir::Value> &operands, llvm::SmallVectorImpl<mlir::Value> &operands,
Fortran::lower::StatementContext &stmtCtx) { Fortran::lower::StatementContext &stmtCtx) {
const auto &deviceTypeValue = deviceTypeClause->v; const Fortran::parser::AccDeviceTypeExprList &deviceTypeExprList =
if (deviceTypeValue) { deviceTypeClause->v;
for (const auto &scalarIntExpr : *deviceTypeValue) { for (const auto &deviceTypeExpr : deviceTypeExprList.v) {
mlir::Value expr = fir::getBase(converter.genExprValue( const auto &expr = std::get<std::optional<Fortran::parser::ScalarIntExpr>>(
*Fortran::semantics::GetExpr(scalarIntExpr), stmtCtx)); deviceTypeExpr.t);
operands.push_back(expr); 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);
} }
} }

View File

@ -62,12 +62,9 @@ TYPE_PARSER("AUTO" >> construct<AccClause>(construct<AccClause::Auto>()) ||
"DEVICE_RESIDENT" >> "DEVICE_RESIDENT" >>
construct<AccClause>(construct<AccClause::DeviceResident>( construct<AccClause>(construct<AccClause::DeviceResident>(
parenthesized(Parser<AccObjectList>{}))) || 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) >> ("DEVICE_TYPE"_tok || "DTYPE"_tok) >>
construct<AccClause>(construct<AccClause::DeviceType>( construct<AccClause>(construct<AccClause::DeviceType>(
parenthesized(maybe(nonemptyList(scalarIntExpr))))) || parenthesized(Parser<AccDeviceTypeExprList>{}))) ||
"FINALIZE" >> construct<AccClause>(construct<AccClause::Finalize>()) || "FINALIZE" >> construct<AccClause>(construct<AccClause::Finalize>()) ||
"FIRSTPRIVATE" >> construct<AccClause>(construct<AccClause::Firstprivate>( "FIRSTPRIVATE" >> construct<AccClause>(construct<AccClause::Firstprivate>(
parenthesized(Parser<AccObjectList>{}))) || parenthesized(Parser<AccObjectList>{}))) ||
@ -137,6 +134,12 @@ TYPE_PARSER(construct<AccSizeExpr>(scalarIntExpr) ||
construct<AccSizeExpr>("*" >> construct<std::optional<ScalarIntExpr>>())) construct<AccSizeExpr>("*" >> construct<std::optional<ScalarIntExpr>>()))
TYPE_PARSER(construct<AccSizeExprList>(nonemptyList(Parser<AccSizeExpr>{}))) 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: // tile size is one of:
// * (represented as an empty std::optional<ScalarIntExpr>) // * (represented as an empty std::optional<ScalarIntExpr>)
// constant-int-expr // constant-int-expr

View File

@ -128,10 +128,8 @@ def ACCC_DeviceResident : Clause<"device_resident"> {
// 2.4 // 2.4
def ACCC_DeviceType : Clause<"device_type"> { def ACCC_DeviceType : Clause<"device_type"> {
let flangClass = "ScalarIntExpr"; let flangClass = "AccDeviceTypeExprList";
let defaultValue = "*"; let defaultValue = "*";
let isValueOptional = true;
let isValueList = true;
} }
// 2.6.6 // 2.6.6