@@ -2379,6 +2379,18 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
23792379 procBindKindAttr);
23802380}
23812381
2382+ static mlir::omp::SectionOp
2383+ genSectionOp (Fortran::lower::AbstractConverter &converter,
2384+ Fortran::lower::pft::Evaluation &eval,
2385+ mlir::Location currentLocation,
2386+ const Fortran::parser::OmpClauseList §ionsClauseList) {
2387+ // Currently only private/firstprivate clause is handled, and
2388+ // all privatization is done within `omp.section` operations.
2389+ return genOpWithBody<mlir::omp::SectionOp>(converter, eval, currentLocation,
2390+ /* outerCombined=*/ false ,
2391+ §ionsClauseList);
2392+ }
2393+
23822394static mlir::omp::SingleOp
23832395genSingleOp (Fortran::lower::AbstractConverter &converter,
23842396 Fortran::lower::pft::Evaluation &eval,
@@ -3375,35 +3387,6 @@ genOMP(Fortran::lower::AbstractConverter &converter,
33753387 genNestedEvaluations (converter, eval);
33763388}
33773389
3378- static void
3379- genOMP (Fortran::lower::AbstractConverter &converter,
3380- Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
3381- const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
3382- mlir::Location currentLocation = converter.getCurrentLocation ();
3383- const Fortran::parser::OpenMPConstruct *parentOmpConstruct =
3384- eval.parentConstruct ->getIf <Fortran::parser::OpenMPConstruct>();
3385- assert (parentOmpConstruct &&
3386- " No enclosing parent OpenMPConstruct on SECTION construct" );
3387- const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct =
3388- std::get_if<Fortran::parser::OpenMPSectionsConstruct>(
3389- &parentOmpConstruct->u );
3390- assert (sectionsConstruct && " SECTION construct must have parent"
3391- " SECTIONS construct" );
3392- const Fortran::parser::OmpClauseList §ionsClauseList =
3393- std::get<Fortran::parser::OmpClauseList>(
3394- std::get<Fortran::parser::OmpBeginSectionsDirective>(
3395- sectionsConstruct->t )
3396- .t );
3397- // Currently only private/firstprivate clause is handled, and
3398- // all privatization is done within `omp.section` operations.
3399- symTable.pushScope ();
3400- genOpWithBody<mlir::omp::SectionOp>(converter, eval, currentLocation,
3401- /* outerCombined=*/ false ,
3402- §ionsClauseList);
3403- genNestedEvaluations (converter, eval);
3404- symTable.popScope ();
3405- }
3406-
34073390static void
34083391genOMP (Fortran::lower::AbstractConverter &converter,
34093392 Fortran::lower::SymMap &symTable, Fortran::lower::pft::Evaluation &eval,
@@ -3447,7 +3430,18 @@ genOMP(Fortran::lower::AbstractConverter &converter,
34473430 /* reductions=*/ nullptr , allocateOperands,
34483431 allocatorOperands, nowaitClauseOperand);
34493432
3450- genNestedEvaluations (converter, eval);
3433+ const auto §ionBlocks =
3434+ std::get<Fortran::parser::OmpSectionBlocks>(sectionsConstruct.t );
3435+ auto &firOpBuilder = converter.getFirOpBuilder ();
3436+ auto ip = firOpBuilder.saveInsertionPoint ();
3437+ for (const auto &[nblock, neval] :
3438+ llvm::zip (sectionBlocks.v , eval.getNestedEvaluations ())) {
3439+ symTable.pushScope ();
3440+ genSectionOp (converter, neval, currentLocation, sectionsClauseList);
3441+ genNestedEvaluations (converter, neval);
3442+ symTable.popScope ();
3443+ firOpBuilder.restoreInsertionPoint (ip);
3444+ }
34513445}
34523446
34533447static void
@@ -3562,7 +3556,8 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
35623556 genOMP (converter, symTable, eval, sectionsConstruct);
35633557 },
35643558 [&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
3565- genOMP (converter, symTable, eval, sectionConstruct);
3559+ // SECTION constructs are handled as a part of SECTIONS.
3560+ llvm_unreachable (" Unexpected standalone OMP SECTION" );
35663561 },
35673562 [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
35683563 genOMP (converter, symTable, eval, semanticsContext, loopConstruct);
0 commit comments