forked from OSchip/llvm-project
[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:
parent
36e24da8eb
commit
015834e455
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue