diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h index 3f9701310ebae..78c148ab02163 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.h +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h @@ -49,9 +49,8 @@ class ClauseProcessor { public: ClauseProcessor(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &clauses) - : converter(converter), semaCtx(semaCtx), - clauses(makeClauses(clauses, semaCtx)) {} + const List &clauses) + : converter(converter), semaCtx(semaCtx), clauses(clauses) {} // 'Unique' clauses: They can appear at most once in the clause list. bool processCollapse( diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.h b/flang/lib/Lower/OpenMP/DataSharingProcessor.h index c11ee299c5d08..ef7b14327278e 100644 --- a/flang/lib/Lower/OpenMP/DataSharingProcessor.h +++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.h @@ -78,13 +78,12 @@ class DataSharingProcessor { public: DataSharingProcessor(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &opClauseList, + const List &clauses, Fortran::lower::pft::Evaluation &eval, bool useDelayedPrivatization = false, Fortran::lower::SymMap *symTable = nullptr) : hasLastPrivateOp(false), converter(converter), - firOpBuilder(converter.getFirOpBuilder()), - clauses(omp::makeClauses(opClauseList, semaCtx)), eval(eval), + firOpBuilder(converter.getFirOpBuilder()), clauses(clauses), eval(eval), useDelayedPrivatization(useDelayedPrivatization), symTable(symTable) {} // Privatisation is split into two steps. diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index bb38082b245ef..4424788e0132e 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -17,6 +17,7 @@ #include "DataSharingProcessor.h" #include "DirectivesCommon.h" #include "ReductionProcessor.h" +#include "Utils.h" #include "flang/Common/idioms.h" #include "flang/Lower/Bridge.h" #include "flang/Lower/ConvertExpr.h" @@ -295,14 +296,15 @@ static void getDeclareTargetInfo( } else if (const auto *clauseList{ Fortran::parser::Unwrap( spec.u)}) { - if (clauseList->v.empty()) { + List clauses = makeClauses(*clauseList, semaCtx); + if (clauses.empty()) { // Case: declare target, implicit capture of function symbolAndClause.emplace_back( mlir::omp::DeclareTargetCaptureClause::to, eval.getOwningProcedure()->getSubprogramSymbol()); } - ClauseProcessor cp(converter, semaCtx, *clauseList); + ClauseProcessor cp(converter, semaCtx, clauses); cp.processDeviceType(clauseOps); cp.processEnter(symbolAndClause); cp.processLink(symbolAndClause); @@ -592,7 +594,7 @@ struct OpWithBodyGenInfo { return *this; } - OpWithBodyGenInfo &setClauses(const Fortran::parser::OmpClauseList *value) { + OpWithBodyGenInfo &setClauses(const List *value) { clauses = value; return *this; } @@ -630,7 +632,7 @@ struct OpWithBodyGenInfo { /// [in] is this an outer operation - prevents privatization. bool outerCombined = false; /// [in] list of clauses to process. - const Fortran::parser::OmpClauseList *clauses = nullptr; + const List *clauses = nullptr; /// [in] if provided, processes the construct's data-sharing attributes. DataSharingProcessor *dsp = nullptr; /// [in] if provided, list of reduction symbols @@ -1020,37 +1022,35 @@ static OpTy genOpWithBody(OpWithBodyGenInfo &info, Args &&...args) { // Code generation functions for clauses //===----------------------------------------------------------------------===// -static void genCriticalDeclareClauses( - Fortran::lower::AbstractConverter &converter, - Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &clauses, mlir::Location loc, - mlir::omp::CriticalClauseOps &clauseOps, llvm::StringRef name) { +static void +genCriticalDeclareClauses(Fortran::lower::AbstractConverter &converter, + Fortran::semantics::SemanticsContext &semaCtx, + const List &clauses, mlir::Location loc, + mlir::omp::CriticalClauseOps &clauseOps, + llvm::StringRef name) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processHint(clauseOps); clauseOps.nameAttr = mlir::StringAttr::get(converter.getFirOpBuilder().getContext(), name); } -static void genFlushClauses( - Fortran::lower::AbstractConverter &converter, - Fortran::semantics::SemanticsContext &semaCtx, - const std::optional &objects, - const std::optional> - &clauses, - mlir::Location loc, llvm::SmallVectorImpl &operandRange) { - if (objects) - genObjectList2(*objects, converter, operandRange); - - if (clauses && clauses->size() > 0) +static void genFlushClauses(Fortran::lower::AbstractConverter &converter, + Fortran::semantics::SemanticsContext &semaCtx, + const ObjectList &objects, + const List &clauses, mlir::Location loc, + llvm::SmallVectorImpl &operandRange) { + if (!objects.empty()) + genObjectList(objects, converter, operandRange); + + if (!clauses.empty()) TODO(converter.getCurrentLocation(), "Handle OmpMemoryOrderClause"); } static void genLoopNestClauses( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OmpClauseList &clauses, mlir::Location loc, - mlir::omp::LoopNestClauseOps &clauseOps, + Fortran::lower::pft::Evaluation &eval, const List &clauses, + mlir::Location loc, mlir::omp::LoopNestClauseOps &clauseOps, llvm::SmallVectorImpl &iv) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processCollapse(loc, eval, clauseOps, iv); @@ -1060,8 +1060,7 @@ static void genLoopNestClauses( static void genOrderedRegionClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &clauses, - mlir::Location loc, + const List &clauses, mlir::Location loc, mlir::omp::OrderedRegionClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processTODO(loc, llvm::omp::Directive::OMPD_ordered); @@ -1070,9 +1069,9 @@ genOrderedRegionClauses(Fortran::lower::AbstractConverter &converter, static void genParallelClauses( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::StatementContext &stmtCtx, - const Fortran::parser::OmpClauseList &clauses, mlir::Location loc, - bool processReduction, mlir::omp::ParallelClauseOps &clauseOps, + Fortran::lower::StatementContext &stmtCtx, const List &clauses, + mlir::Location loc, bool processReduction, + mlir::omp::ParallelClauseOps &clauseOps, llvm::SmallVectorImpl &reductionTypes, llvm::SmallVectorImpl &reductionSyms) { ClauseProcessor cp(converter, semaCtx, clauses); @@ -1091,8 +1090,7 @@ static void genParallelClauses( static void genSectionsClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &clauses, - mlir::Location loc, + const List &clauses, mlir::Location loc, bool clausesFromBeginSections, mlir::omp::SectionsClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); @@ -1107,8 +1105,7 @@ static void genSectionsClauses(Fortran::lower::AbstractConverter &converter, static void genSimdClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &clauses, - mlir::Location loc, + const List &clauses, mlir::Location loc, mlir::omp::SimdClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processIf(llvm::omp::Directive::OMPD_simd, clauseOps); @@ -1124,9 +1121,8 @@ static void genSimdClauses(Fortran::lower::AbstractConverter &converter, static void genSingleClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &beginClauses, - const Fortran::parser::OmpClauseList &endClauses, - mlir::Location loc, + const List &beginClauses, + const List &endClauses, mlir::Location loc, mlir::omp::SingleClauseOps &clauseOps) { ClauseProcessor bcp(converter, semaCtx, beginClauses); bcp.processAllocate(clauseOps); @@ -1140,9 +1136,8 @@ static void genSingleClauses(Fortran::lower::AbstractConverter &converter, static void genTargetClauses( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::StatementContext &stmtCtx, - const Fortran::parser::OmpClauseList &clauses, mlir::Location loc, - bool processHostOnlyClauses, bool processReduction, + Fortran::lower::StatementContext &stmtCtx, const List &clauses, + mlir::Location loc, bool processHostOnlyClauses, bool processReduction, mlir::omp::TargetClauseOps &clauseOps, llvm::SmallVectorImpl &mapSyms, llvm::SmallVectorImpl &mapLocs, @@ -1177,9 +1172,8 @@ static void genTargetClauses( static void genTargetDataClauses( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::StatementContext &stmtCtx, - const Fortran::parser::OmpClauseList &clauses, mlir::Location loc, - mlir::omp::TargetDataClauseOps &clauseOps, + Fortran::lower::StatementContext &stmtCtx, const List &clauses, + mlir::Location loc, mlir::omp::TargetDataClauseOps &clauseOps, llvm::SmallVectorImpl &useDeviceTypes, llvm::SmallVectorImpl &useDeviceLocs, llvm::SmallVectorImpl &useDeviceSyms) { @@ -1210,9 +1204,8 @@ static void genTargetDataClauses( static void genTargetEnterExitUpdateDataClauses( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::StatementContext &stmtCtx, - const Fortran::parser::OmpClauseList &clauses, mlir::Location loc, - llvm::omp::Directive directive, + Fortran::lower::StatementContext &stmtCtx, const List &clauses, + mlir::Location loc, llvm::omp::Directive directive, mlir::omp::TargetEnterExitUpdateDataClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processDepend(clauseOps); @@ -1231,8 +1224,7 @@ static void genTargetEnterExitUpdateDataClauses( static void genTaskClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::StatementContext &stmtCtx, - const Fortran::parser::OmpClauseList &clauses, - mlir::Location loc, + const List &clauses, mlir::Location loc, mlir::omp::TaskClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processAllocate(clauseOps); @@ -1251,20 +1243,17 @@ static void genTaskClauses(Fortran::lower::AbstractConverter &converter, static void genTaskgroupClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &clauses, - mlir::Location loc, + const List &clauses, mlir::Location loc, mlir::omp::TaskgroupClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processAllocate(clauseOps); - cp.processTODO(loc, llvm::omp::Directive::OMPD_taskgroup); } static void genTaskwaitClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - const Fortran::parser::OmpClauseList &clauses, - mlir::Location loc, + const List &clauses, mlir::Location loc, mlir::omp::TaskwaitClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processTODO( @@ -1274,8 +1263,7 @@ static void genTaskwaitClauses(Fortran::lower::AbstractConverter &converter, static void genTeamsClauses(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::StatementContext &stmtCtx, - const Fortran::parser::OmpClauseList &clauses, - mlir::Location loc, + const List &clauses, mlir::Location loc, mlir::omp::TeamsClauseOps &clauseOps) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processAllocate(clauseOps); @@ -1292,9 +1280,8 @@ static void genWsloopClauses( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::StatementContext &stmtCtx, - Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OmpClauseList &beginClauses, - const Fortran::parser::OmpClauseList *endClauses, mlir::Location loc, + Fortran::lower::pft::Evaluation &eval, const List &beginClauses, + const List &endClauses, mlir::Location loc, mlir::omp::WsloopClauseOps &clauseOps, llvm::SmallVectorImpl &iv, llvm::SmallVectorImpl &reductionTypes, @@ -1311,8 +1298,8 @@ static void genWsloopClauses( if (ReductionProcessor::doReductionByRef(clauseOps.reductionVars)) clauseOps.reductionByRefAttr = firOpBuilder.getUnitAttr(); - if (endClauses) { - ClauseProcessor ecp(converter, semaCtx, *endClauses); + if (!endClauses.empty()) { + ClauseProcessor ecp(converter, semaCtx, endClauses); ecp.processNowait(clauseOps); } @@ -1335,8 +1322,7 @@ static mlir::omp::CriticalOp genCriticalOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList, + mlir::Location loc, const List &clauses, const std::optional &name) { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); mlir::FlatSymbolRefAttr nameAttr; @@ -1347,7 +1333,7 @@ genCriticalOp(Fortran::lower::AbstractConverter &converter, auto global = mod.lookupSymbol(nameStr); if (!global) { mlir::omp::CriticalClauseOps clauseOps; - genCriticalDeclareClauses(converter, semaCtx, clauseList, loc, clauseOps, + genCriticalDeclareClauses(converter, semaCtx, clauses, loc, clauseOps, nameStr); mlir::OpBuilder modBuilder(mod.getBodyRegion()); @@ -1368,8 +1354,7 @@ static mlir::omp::DistributeOp genDistributeOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + mlir::Location loc, const List &clauses) { TODO(loc, "Distribute construct"); return nullptr; } @@ -1378,12 +1363,9 @@ static mlir::omp::FlushOp genFlushOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, mlir::Location loc, - const std::optional &objectList, - const std::optional> - &clauseList) { + const ObjectList &objects, const List &clauses) { llvm::SmallVector operandRange; - genFlushClauses(converter, semaCtx, objectList, clauseList, loc, - operandRange); + genFlushClauses(converter, semaCtx, objects, clauses, loc, operandRange); return converter.getFirOpBuilder().create( converter.getCurrentLocation(), operandRange); @@ -1404,7 +1386,7 @@ static mlir::omp::OrderedOp genOrderedOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + const List &clauses) { TODO(loc, "OMPD_ordered"); return nullptr; } @@ -1413,10 +1395,9 @@ static mlir::omp::OrderedRegionOp genOrderedRegionOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + mlir::Location loc, const List &clauses) { mlir::omp::OrderedRegionClauseOps clauseOps; - genOrderedRegionClauses(converter, semaCtx, clauseList, loc, clauseOps); + genOrderedRegionClauses(converter, semaCtx, clauses, loc, clauseOps); return genOpWithBody( OpWithBodyGenInfo(converter, semaCtx, loc, eval, @@ -1430,8 +1411,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter, Fortran::lower::SymMap &symTable, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList, + mlir::Location loc, const List &clauses, bool outerCombined = false) { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); Fortran::lower::StatementContext stmtCtx; @@ -1439,7 +1419,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter, llvm::SmallVector privateSyms; llvm::SmallVector reductionTypes; llvm::SmallVector reductionSyms; - genParallelClauses(converter, semaCtx, stmtCtx, clauseList, loc, + genParallelClauses(converter, semaCtx, stmtCtx, clauses, loc, /*processReduction=*/!outerCombined, clauseOps, reductionTypes, reductionSyms); @@ -1453,7 +1433,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter, llvm::omp::Directive::OMPD_parallel) .setGenNested(genNested) .setOuterCombined(outerCombined) - .setClauses(&clauseList) + .setClauses(&clauses) .setReductions(&reductionSyms, &reductionTypes) .setGenRegionEntryCb(reductionCallback); @@ -1461,7 +1441,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter, return genOpWithBody(genInfo, clauseOps); bool privatize = !outerCombined; - DataSharingProcessor dsp(converter, semaCtx, clauseList, eval, + DataSharingProcessor dsp(converter, semaCtx, clauses, eval, /*useDelayedPrivatization=*/true, &symTable); if (privatize) @@ -1508,15 +1488,14 @@ static mlir::omp::SectionOp genSectionOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + mlir::Location loc, const List &clauses) { // Currently only private/firstprivate clause is handled, and // all privatization is done within `omp.section` operations. return genOpWithBody( OpWithBodyGenInfo(converter, semaCtx, loc, eval, llvm::omp::Directive::OMPD_section) .setGenNested(genNested) - .setClauses(&clauseList)); + .setClauses(&clauses)); } static mlir::omp::SectionsOp @@ -1535,18 +1514,17 @@ static mlir::omp::SimdOp genSimdOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + const List &clauses) { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); - DataSharingProcessor dsp(converter, semaCtx, clauseList, eval); + DataSharingProcessor dsp(converter, semaCtx, clauses, eval); dsp.processStep1(); Fortran::lower::StatementContext stmtCtx; mlir::omp::LoopNestClauseOps loopClauseOps; mlir::omp::SimdClauseOps simdClauseOps; llvm::SmallVector iv; - genLoopNestClauses(converter, semaCtx, eval, clauseList, loc, loopClauseOps, - iv); - genSimdClauses(converter, semaCtx, clauseList, loc, simdClauseOps); + genLoopNestClauses(converter, semaCtx, eval, clauses, loc, loopClauseOps, iv); + genSimdClauses(converter, semaCtx, clauses, loc, simdClauseOps); // Create omp.simd wrapper. auto simdOp = firOpBuilder.create(loc, simdClauseOps); @@ -1559,8 +1537,7 @@ genSimdOp(Fortran::lower::AbstractConverter &converter, // Create nested omp.loop_nest and fill body with loop contents. auto loopOp = firOpBuilder.create(loc, loopClauseOps); - auto *nestedEval = - getCollapsedLoopEval(eval, Fortran::lower::getCollapseValue(clauseList)); + auto *nestedEval = getCollapsedLoopEval(eval, getCollapseValue(clauses)); auto ivCallback = [&](mlir::Operation *op) { return genLoopVars(op, converter, loc, iv); @@ -1569,7 +1546,7 @@ genSimdOp(Fortran::lower::AbstractConverter &converter, createBodyOfOp(*loopOp, OpWithBodyGenInfo(converter, semaCtx, loc, *nestedEval, llvm::omp::Directive::OMPD_simd) - .setClauses(&clauseList) + .setClauses(&clauses) .setDataSharingProcessor(&dsp) .setGenRegionEntryCb(ivCallback)); @@ -1580,18 +1557,17 @@ static mlir::omp::SingleOp genSingleOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList &endClauseList) { + mlir::Location loc, const List &beginClauses, + const List &endClauses) { mlir::omp::SingleClauseOps clauseOps; - genSingleClauses(converter, semaCtx, beginClauseList, endClauseList, loc, + genSingleClauses(converter, semaCtx, beginClauses, endClauses, loc, clauseOps); return genOpWithBody( OpWithBodyGenInfo(converter, semaCtx, loc, eval, llvm::omp::Directive::OMPD_single) .setGenNested(genNested) - .setClauses(&beginClauseList), + .setClauses(&beginClauses), clauseOps); } @@ -1599,8 +1575,7 @@ static mlir::omp::TargetOp genTargetOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList, + mlir::Location loc, const List &clauses, bool outerCombined = false) { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); Fortran::lower::StatementContext stmtCtx; @@ -1614,7 +1589,7 @@ genTargetOp(Fortran::lower::AbstractConverter &converter, deviceAddrSyms; llvm::SmallVector mapLocs, devicePtrLocs, deviceAddrLocs; llvm::SmallVector mapTypes, devicePtrTypes, deviceAddrTypes; - genTargetClauses(converter, semaCtx, stmtCtx, clauseList, loc, + genTargetClauses(converter, semaCtx, stmtCtx, clauses, loc, processHostOnlyClauses, /*processReduction=*/outerCombined, clauseOps, mapSyms, mapLocs, mapTypes, deviceAddrSyms, deviceAddrLocs, deviceAddrTypes, devicePtrSyms, @@ -1714,14 +1689,13 @@ static mlir::omp::TargetDataOp genTargetDataOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + mlir::Location loc, const List &clauses) { Fortran::lower::StatementContext stmtCtx; mlir::omp::TargetDataClauseOps clauseOps; llvm::SmallVector useDeviceTypes; llvm::SmallVector useDeviceLocs; llvm::SmallVector useDeviceSyms; - genTargetDataClauses(converter, semaCtx, stmtCtx, clauseList, loc, clauseOps, + genTargetDataClauses(converter, semaCtx, stmtCtx, clauses, loc, clauseOps, useDeviceTypes, useDeviceLocs, useDeviceSyms); auto targetDataOp = @@ -1733,10 +1707,11 @@ genTargetDataOp(Fortran::lower::AbstractConverter &converter, } template -static OpTy genTargetEnterExitUpdateDataOp( - Fortran::lower::AbstractConverter &converter, - Fortran::semantics::SemanticsContext &semaCtx, mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { +static OpTy +genTargetEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter, + Fortran::semantics::SemanticsContext &semaCtx, + mlir::Location loc, + const List &clauses) { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); Fortran::lower::StatementContext stmtCtx; @@ -1751,9 +1726,10 @@ static OpTy genTargetEnterExitUpdateDataOp( } else { llvm_unreachable("Unexpected TARGET DATA construct"); } + mlir::omp::TargetEnterExitUpdateDataClauseOps clauseOps; - genTargetEnterExitUpdateDataClauses(converter, semaCtx, stmtCtx, clauseList, - loc, directive, clauseOps); + genTargetEnterExitUpdateDataClauses(converter, semaCtx, stmtCtx, clauses, loc, + directive, clauseOps); return firOpBuilder.create(loc, clauseOps); } @@ -1762,17 +1738,16 @@ static mlir::omp::TaskOp genTaskOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + mlir::Location loc, const List &clauses) { Fortran::lower::StatementContext stmtCtx; mlir::omp::TaskClauseOps clauseOps; - genTaskClauses(converter, semaCtx, stmtCtx, clauseList, loc, clauseOps); + genTaskClauses(converter, semaCtx, stmtCtx, clauses, loc, clauseOps); return genOpWithBody( OpWithBodyGenInfo(converter, semaCtx, loc, eval, llvm::omp::Directive::OMPD_task) .setGenNested(genNested) - .setClauses(&clauseList), + .setClauses(&clauses), clauseOps); } @@ -1780,16 +1755,15 @@ static mlir::omp::TaskgroupOp genTaskgroupOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + mlir::Location loc, const List &clauses) { mlir::omp::TaskgroupClauseOps clauseOps; - genTaskgroupClauses(converter, semaCtx, clauseList, loc, clauseOps); + genTaskgroupClauses(converter, semaCtx, clauses, loc, clauseOps); return genOpWithBody( OpWithBodyGenInfo(converter, semaCtx, loc, eval, llvm::omp::Directive::OMPD_taskgroup) .setGenNested(genNested) - .setClauses(&clauseList), + .setClauses(&clauses), clauseOps); } @@ -1797,7 +1771,7 @@ static mlir::omp::TaskloopOp genTaskloopOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + const List &clauses) { TODO(loc, "Taskloop construct"); } @@ -1805,9 +1779,9 @@ static mlir::omp::TaskwaitOp genTaskwaitOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, mlir::Location loc, - const Fortran::parser::OmpClauseList &clauseList) { + const List &clauses) { mlir::omp::TaskwaitClauseOps clauseOps; - genTaskwaitClauses(converter, semaCtx, clauseList, loc, clauseOps); + genTaskwaitClauses(converter, semaCtx, clauses, loc, clauseOps); return converter.getFirOpBuilder().create(loc, clauseOps); } @@ -1823,18 +1797,18 @@ static mlir::omp::TeamsOp genTeamsOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, bool genNested, - mlir::Location loc, const Fortran::parser::OmpClauseList &clauseList, + mlir::Location loc, const List &clauses, bool outerCombined = false) { Fortran::lower::StatementContext stmtCtx; mlir::omp::TeamsClauseOps clauseOps; - genTeamsClauses(converter, semaCtx, stmtCtx, clauseList, loc, clauseOps); + genTeamsClauses(converter, semaCtx, stmtCtx, clauses, loc, clauseOps); return genOpWithBody( OpWithBodyGenInfo(converter, semaCtx, loc, eval, llvm::omp::Directive::OMPD_teams) .setGenNested(genNested) .setOuterCombined(outerCombined) - .setClauses(&clauseList), + .setClauses(&clauses), clauseOps); } @@ -1842,9 +1816,8 @@ static mlir::omp::WsloopOp genWsloopOp(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, mlir::Location loc, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList *endClauseList) { - DataSharingProcessor dsp(converter, semaCtx, beginClauseList, eval); + const List &beginClauses, const List &endClauses) { + DataSharingProcessor dsp(converter, semaCtx, beginClauses, eval); dsp.processStep1(); Fortran::lower::StatementContext stmtCtx; @@ -1852,12 +1825,10 @@ genWsloopOp(Fortran::lower::AbstractConverter &converter, llvm::SmallVector iv; llvm::SmallVector reductionTypes; llvm::SmallVector reductionSyms; - genWsloopClauses(converter, semaCtx, stmtCtx, eval, beginClauseList, - endClauseList, loc, clauseOps, iv, reductionTypes, - reductionSyms); + genWsloopClauses(converter, semaCtx, stmtCtx, eval, beginClauses, endClauses, + loc, clauseOps, iv, reductionTypes, reductionSyms); - auto *nestedEval = getCollapsedLoopEval( - eval, Fortran::lower::getCollapseValue(beginClauseList)); + auto *nestedEval = getCollapsedLoopEval(eval, getCollapseValue(beginClauses)); auto ivCallback = [&](mlir::Operation *op) { return genLoopAndReductionVars(op, converter, loc, iv, reductionSyms, @@ -1867,7 +1838,7 @@ genWsloopOp(Fortran::lower::AbstractConverter &converter, return genOpWithBody( OpWithBodyGenInfo(converter, semaCtx, loc, *nestedEval, llvm::omp::Directive::OMPD_do) - .setClauses(&beginClauseList) + .setClauses(&beginClauses) .setDataSharingProcessor(&dsp) .setReductions(&reductionSyms, &reductionTypes) .setGenRegionEntryCb(ivCallback), @@ -1881,38 +1852,35 @@ genWsloopOp(Fortran::lower::AbstractConverter &converter, static void genCompositeDistributeParallelDo( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList *endClauseList, mlir::Location loc) { + Fortran::lower::pft::Evaluation &eval, const List &beginClauses, + const List &endClauses, mlir::Location loc) { TODO(loc, "Composite DISTRIBUTE PARALLEL DO"); } static void genCompositeDistributeParallelDoSimd( Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList *endClauseList, mlir::Location loc) { + Fortran::lower::pft::Evaluation &eval, const List &beginClauses, + const List &endClauses, mlir::Location loc) { TODO(loc, "Composite DISTRIBUTE PARALLEL DO SIMD"); } -static void genCompositeDistributeSimd( - Fortran::lower::AbstractConverter &converter, - Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList *endClauseList, mlir::Location loc) { +static void +genCompositeDistributeSimd(Fortran::lower::AbstractConverter &converter, + Fortran::semantics::SemanticsContext &semaCtx, + Fortran::lower::pft::Evaluation &eval, + const List &beginClauses, + const List &endClauses, mlir::Location loc) { TODO(loc, "Composite DISTRIBUTE SIMD"); } -static void -genCompositeDoSimd(Fortran::lower::AbstractConverter &converter, - Fortran::semantics::SemanticsContext &semaCtx, - Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList *endClauseList, - mlir::Location loc) { - ClauseProcessor cp(converter, semaCtx, beginClauseList); +static void genCompositeDoSimd(Fortran::lower::AbstractConverter &converter, + Fortran::semantics::SemanticsContext &semaCtx, + Fortran::lower::pft::Evaluation &eval, + const List &beginClauses, + const List &endClauses, + mlir::Location loc) { + ClauseProcessor cp(converter, semaCtx, beginClauses); cp.processTODO( loc, llvm::omp::OMPD_do_simd); @@ -1924,16 +1892,15 @@ genCompositeDoSimd(Fortran::lower::AbstractConverter &converter, // When support for vectorization is enabled, then we need to add handling of // if clause. Currently if clause can be skipped because we always assume // SIMD length = 1. - genWsloopOp(converter, semaCtx, eval, loc, beginClauseList, endClauseList); + genWsloopOp(converter, semaCtx, eval, loc, beginClauses, endClauses); } static void genCompositeTaskloopSimd(Fortran::lower::AbstractConverter &converter, Fortran::semantics::SemanticsContext &semaCtx, Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OmpClauseList &beginClauseList, - const Fortran::parser::OmpClauseList *endClauseList, - mlir::Location loc) { + const List &beginClauses, + const List &endClauses, mlir::Location loc) { TODO(loc, "Composite TASKLOOP SIMD"); } @@ -2042,8 +2009,9 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, const auto &directive = std::get( simpleStandaloneConstruct.t); - const auto &clauseList = - std::get(simpleStandaloneConstruct.t); + List clauses = makeClauses( + std::get(simpleStandaloneConstruct.t), + semaCtx); mlir::Location currentLocation = converter.genLocation(directive.source); switch (directive.v) { @@ -2053,29 +2021,29 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, genBarrierOp(converter, semaCtx, eval, currentLocation); break; case llvm::omp::Directive::OMPD_taskwait: - genTaskwaitOp(converter, semaCtx, eval, currentLocation, clauseList); + genTaskwaitOp(converter, semaCtx, eval, currentLocation, clauses); break; case llvm::omp::Directive::OMPD_taskyield: genTaskyieldOp(converter, semaCtx, eval, currentLocation); break; case llvm::omp::Directive::OMPD_target_data: genTargetDataOp(converter, semaCtx, eval, /*genNested=*/true, - currentLocation, clauseList); + currentLocation, clauses); break; case llvm::omp::Directive::OMPD_target_enter_data: genTargetEnterExitUpdateDataOp( - converter, semaCtx, currentLocation, clauseList); + converter, semaCtx, currentLocation, clauses); break; case llvm::omp::Directive::OMPD_target_exit_data: genTargetEnterExitUpdateDataOp( - converter, semaCtx, currentLocation, clauseList); + converter, semaCtx, currentLocation, clauses); break; case llvm::omp::Directive::OMPD_target_update: genTargetEnterExitUpdateDataOp( - converter, semaCtx, currentLocation, clauseList); + converter, semaCtx, currentLocation, clauses); break; case llvm::omp::Directive::OMPD_ordered: - genOrderedOp(converter, semaCtx, eval, currentLocation, clauseList); + genOrderedOp(converter, semaCtx, eval, currentLocation, clauses); break; } } @@ -2092,8 +2060,14 @@ genOMP(Fortran::lower::AbstractConverter &converter, const auto &clauseList = std::get>>( flushConstruct.t); + ObjectList objects = + objectList ? makeObjects(*objectList, semaCtx) : ObjectList{}; + List clauses = + clauseList ? makeList(*clauseList, + [&](auto &&s) { return makeClause(s.v, semaCtx); }) + : List{}; mlir::Location currentLocation = converter.genLocation(verbatim.source); - genFlushOp(converter, semaCtx, eval, currentLocation, objectList, clauseList); + genFlushOp(converter, semaCtx, eval, currentLocation, objects, clauses); } static void @@ -2198,46 +2172,46 @@ genOMP(Fortran::lower::AbstractConverter &converter, converter.genLocation(beginBlockDirective.source); const auto origDirective = std::get(beginBlockDirective.t).v; - const auto &beginClauseList = - std::get(beginBlockDirective.t); - const auto &endClauseList = - std::get(endBlockDirective.t); + List beginClauses = makeClauses( + std::get(beginBlockDirective.t), semaCtx); + List endClauses = makeClauses( + std::get(endBlockDirective.t), semaCtx); assert(llvm::omp::blockConstructSet.test(origDirective) && "Expected block construct"); - for (const Fortran::parser::OmpClause &clause : beginClauseList.v) { + for (const Clause &clause : beginClauses) { mlir::Location clauseLocation = converter.genLocation(clause.source); - if (!std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u) && - !std::get_if(&clause.u)) { + if (!std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u) && + !std::get_if(&clause.u)) { TODO(clauseLocation, "OpenMP Block construct clause"); } } - for (const auto &clause : endClauseList.v) { + for (const Clause &clause : endClauses) { mlir::Location clauseLocation = converter.genLocation(clause.source); - if (!std::get_if(&clause.u) && - !std::get_if(&clause.u)) + if (!std::get_if(&clause.u) && + !std::get_if(&clause.u)) TODO(clauseLocation, "OpenMP Block construct clause"); } @@ -2256,44 +2230,44 @@ genOMP(Fortran::lower::AbstractConverter &converter, case llvm::omp::Directive::OMPD_ordered: // 2.17.9 ORDERED construct. genOrderedRegionOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList); + beginClauses); break; case llvm::omp::Directive::OMPD_parallel: // 2.6 PARALLEL construct. genParallelOp(converter, symTable, semaCtx, eval, genNested, - currentLocation, beginClauseList, outerCombined); + currentLocation, beginClauses, outerCombined); break; case llvm::omp::Directive::OMPD_single: // 2.8.2 SINGLE construct. genSingleOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList, endClauseList); + beginClauses, endClauses); break; case llvm::omp::Directive::OMPD_target: // 2.12.5 TARGET construct. genTargetOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList, outerCombined); + beginClauses, outerCombined); break; case llvm::omp::Directive::OMPD_target_data: // 2.12.2 TARGET DATA construct. genTargetDataOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList); + beginClauses); break; case llvm::omp::Directive::OMPD_task: // 2.10.1 TASK construct. genTaskOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList); + beginClauses); break; case llvm::omp::Directive::OMPD_taskgroup: // 2.17.6 TASKGROUP construct. genTaskgroupOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList); + beginClauses); break; case llvm::omp::Directive::OMPD_teams: // 2.7 TEAMS construct. // FIXME Pass the outerCombined argument or rename it to better describe // what it represents if it must always be `false` in this context. genTeamsOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList); + beginClauses); break; case llvm::omp::Directive::OMPD_workshare: // 2.8.3 WORKSHARE construct. @@ -2301,7 +2275,7 @@ genOMP(Fortran::lower::AbstractConverter &converter, // implementation for this feature will come later. For the codes // that use this construct, add a single construct for now. genSingleOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList, endClauseList); + beginClauses, endClauses); break; default: llvm_unreachable("Unexpected block construct"); @@ -2319,11 +2293,12 @@ genOMP(Fortran::lower::AbstractConverter &converter, const Fortran::parser::OpenMPCriticalConstruct &criticalConstruct) { const auto &cd = std::get(criticalConstruct.t); - const auto &clauseList = std::get(cd.t); + List clauses = + makeClauses(std::get(cd.t), semaCtx); const auto &name = std::get>(cd.t); mlir::Location currentLocation = converter.getCurrentLocation(); genCriticalOp(converter, semaCtx, eval, /*genNested=*/true, currentLocation, - clauseList, name); + clauses, name); } static void @@ -2342,8 +2317,8 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, const Fortran::parser::OpenMPLoopConstruct &loopConstruct) { const auto &beginLoopDirective = std::get(loopConstruct.t); - const auto &beginClauseList = - std::get(beginLoopDirective.t); + List beginClauses = makeClauses( + std::get(beginLoopDirective.t), semaCtx); mlir::Location currentLocation = converter.genLocation(beginLoopDirective.source); const auto origDirective = @@ -2352,15 +2327,15 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, assert(llvm::omp::loopConstructSet.test(origDirective) && "Expected loop construct"); - const auto *endClauseList = [&]() { - using RetTy = const Fortran::parser::OmpClauseList *; + List endClauses = [&]() { if (auto &endLoopDirective = std::get>( loopConstruct.t)) { - return RetTy( - &std::get((*endLoopDirective).t)); + return makeClauses( + std::get(endLoopDirective->t), + semaCtx); } - return RetTy(); + return List{}; }(); std::optional nextDir = origDirective; @@ -2372,30 +2347,29 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, switch (leafDir) { case llvm::omp::Directive::OMPD_distribute_parallel_do: // 2.9.4.3 DISTRIBUTE PARALLEL Worksharing-Loop construct. - genCompositeDistributeParallelDo(converter, semaCtx, eval, - beginClauseList, endClauseList, - currentLocation); + genCompositeDistributeParallelDo(converter, semaCtx, eval, beginClauses, + endClauses, currentLocation); break; case llvm::omp::Directive::OMPD_distribute_parallel_do_simd: // 2.9.4.4 DISTRIBUTE PARALLEL Worksharing-Loop SIMD construct. genCompositeDistributeParallelDoSimd(converter, semaCtx, eval, - beginClauseList, endClauseList, + beginClauses, endClauses, currentLocation); break; case llvm::omp::Directive::OMPD_distribute_simd: // 2.9.4.2 DISTRIBUTE SIMD construct. - genCompositeDistributeSimd(converter, semaCtx, eval, beginClauseList, - endClauseList, currentLocation); + genCompositeDistributeSimd(converter, semaCtx, eval, beginClauses, + endClauses, currentLocation); break; case llvm::omp::Directive::OMPD_do_simd: // 2.9.3.2 Worksharing-Loop SIMD construct. - genCompositeDoSimd(converter, semaCtx, eval, beginClauseList, - endClauseList, currentLocation); + genCompositeDoSimd(converter, semaCtx, eval, beginClauses, endClauses, + currentLocation); break; case llvm::omp::Directive::OMPD_taskloop_simd: // 2.10.3 TASKLOOP SIMD construct. - genCompositeTaskloopSimd(converter, semaCtx, eval, beginClauseList, - endClauseList, currentLocation); + genCompositeTaskloopSimd(converter, semaCtx, eval, beginClauses, + endClauses, currentLocation); break; default: llvm_unreachable("Unexpected composite construct"); @@ -2406,45 +2380,44 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, case llvm::omp::Directive::OMPD_distribute: // 2.9.4.1 DISTRIBUTE construct. genDistributeOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList); + beginClauses); break; case llvm::omp::Directive::OMPD_do: // 2.9.2 Worksharing-Loop construct. - genWsloopOp(converter, semaCtx, eval, currentLocation, beginClauseList, - endClauseList); + genWsloopOp(converter, semaCtx, eval, currentLocation, beginClauses, + endClauses); break; case llvm::omp::Directive::OMPD_parallel: // 2.6 PARALLEL construct. // FIXME This is not necessarily always the outer leaf construct of a - // combined construct in this context (e.g. DISTRIBUTE PARALLEL DO). + // combined construct in this constext (e.g. distribute parallel do). // Maybe rename the argument if it represents something else or // initialize it properly. genParallelOp(converter, symTable, semaCtx, eval, genNested, - currentLocation, beginClauseList, + currentLocation, beginClauses, /*outerCombined=*/true); break; case llvm::omp::Directive::OMPD_simd: // 2.9.3.1 SIMD construct. - genSimdOp(converter, semaCtx, eval, currentLocation, beginClauseList); + genSimdOp(converter, semaCtx, eval, currentLocation, beginClauses); break; case llvm::omp::Directive::OMPD_target: // 2.12.5 TARGET construct. genTargetOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList, /*outerCombined=*/true); + beginClauses, /*outerCombined=*/true); break; case llvm::omp::Directive::OMPD_taskloop: // 2.10.2 TASKLOOP construct. - genTaskloopOp(converter, semaCtx, eval, currentLocation, - beginClauseList); + genTaskloopOp(converter, semaCtx, eval, currentLocation, beginClauses); break; case llvm::omp::Directive::OMPD_teams: // 2.7 TEAMS construct. // FIXME This is not necessarily always the outer leaf construct of a - // combined construct in this constext (e.g. TARGET TEAMS DISTRIBUTE). + // combined construct in this constext (e.g. target teams distribute). // Maybe rename the argument if it represents something else or // initialize it properly. genTeamsOp(converter, semaCtx, eval, genNested, currentLocation, - beginClauseList, /*outerCombined=*/true); + beginClauses, /*outerCombined=*/true); break; case llvm::omp::Directive::OMPD_loop: case llvm::omp::Directive::OMPD_masked: @@ -2480,14 +2453,15 @@ genOMP(Fortran::lower::AbstractConverter &converter, const Fortran::parser::OpenMPSectionsConstruct §ionsConstruct) { const auto &beginSectionsDirective = std::get(sectionsConstruct.t); - const auto &beginClauseList = - std::get(beginSectionsDirective.t); + List beginClauses = makeClauses( + std::get(beginSectionsDirective.t), + semaCtx); // Process clauses before optional omp.parallel, so that new variables are // allocated outside of the parallel region mlir::Location currentLocation = converter.getCurrentLocation(); mlir::omp::SectionsClauseOps clauseOps; - genSectionsClauses(converter, semaCtx, beginClauseList, currentLocation, + genSectionsClauses(converter, semaCtx, beginClauses, currentLocation, /*clausesFromBeginSections=*/true, clauseOps); // Parallel wrapper of PARALLEL SECTIONS construct @@ -2496,14 +2470,15 @@ genOMP(Fortran::lower::AbstractConverter &converter, .v; if (dir == llvm::omp::Directive::OMPD_parallel_sections) { genParallelOp(converter, symTable, semaCtx, eval, - /*genNested=*/false, currentLocation, beginClauseList, + /*genNested=*/false, currentLocation, beginClauses, /*outerCombined=*/true); } else { const auto &endSectionsDirective = std::get(sectionsConstruct.t); - const auto &endClauseList = - std::get(endSectionsDirective.t); - genSectionsClauses(converter, semaCtx, endClauseList, currentLocation, + List endClauses = makeClauses( + std::get(endSectionsDirective.t), + semaCtx); + genSectionsClauses(converter, semaCtx, endClauses, currentLocation, /*clausesFromBeginSections=*/false, clauseOps); } @@ -2519,7 +2494,7 @@ genOMP(Fortran::lower::AbstractConverter &converter, llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) { symTable.pushScope(); genSectionOp(converter, semaCtx, neval, /*genNested=*/true, currentLocation, - beginClauseList); + beginClauses); symTable.popScope(); firOpBuilder.restoreInsertionPoint(ip); } diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index b9c0660aa4da8..da3f2be73e509 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -36,6 +36,17 @@ namespace Fortran { namespace lower { namespace omp { +int64_t getCollapseValue(const List &clauses) { + auto iter = llvm::find_if(clauses, [](const Clause &clause) { + return clause.id == llvm::omp::Clause::OMPC_collapse; + }); + if (iter != clauses.end()) { + const auto &collapse = std::get(iter->u); + return evaluate::ToInt64(collapse.v).value(); + } + return 1; +} + void genObjectList(const ObjectList &objects, Fortran::lower::AbstractConverter &converter, llvm::SmallVectorImpl &operands) { @@ -52,25 +63,6 @@ void genObjectList(const ObjectList &objects, } } -void genObjectList2(const Fortran::parser::OmpObjectList &objectList, - Fortran::lower::AbstractConverter &converter, - llvm::SmallVectorImpl &operands) { - auto addOperands = [&](Fortran::lower::SymbolRef sym) { - const mlir::Value variable = converter.getSymbolAddress(sym); - if (variable) { - operands.push_back(variable); - } else if (const auto *details = - sym->detailsIf()) { - operands.push_back(converter.getSymbolAddress(details->symbol())); - converter.copySymbolBinding(details->symbol(), sym); - } - }; - for (const Fortran::parser::OmpObject &ompObject : objectList.v) { - Fortran::semantics::Symbol *sym = getOmpObjectSymbol(ompObject); - addOperands(*sym); - } -} - mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter, std::size_t loopVarTypeSize) { // OpenMP runtime requires 32-bit or 64-bit loop variables. diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index 4074bf73987d5..b3a9f7f30c98b 100644 --- a/flang/lib/Lower/OpenMP/Utils.h +++ b/flang/lib/Lower/OpenMP/Utils.h @@ -58,6 +58,8 @@ void gatherFuncAndVarSyms( const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause, llvm::SmallVectorImpl &symbolAndClause); +int64_t getCollapseValue(const List &clauses); + Fortran::semantics::Symbol * getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject); @@ -65,10 +67,6 @@ void genObjectList(const ObjectList &objects, Fortran::lower::AbstractConverter &converter, llvm::SmallVectorImpl &operands); -void genObjectList2(const Fortran::parser::OmpObjectList &objectList, - Fortran::lower::AbstractConverter &converter, - llvm::SmallVectorImpl &operands); - } // namespace omp } // namespace lower } // namespace Fortran