From 22f6e97d24f6e7190a447fd60e11e8ea03fd8356 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 15 Jan 2024 11:24:28 -0600 Subject: [PATCH] [Flang][OpenMP] Handle SECTION construct from within SECTIONS (#77759) Introduce `genSectionOp`, invoke it from the SECTIONS construct for each nested SECTION construct. This makes it unnecessary to embed OpenMPSectionConstruct inside of OpenMPConstruct anymore. Recursive lowering [3/5] --- flang/lib/Lower/OpenMP.cpp | 60 +++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp index 50a96d444b3525..4f7c99a6d2b840 100644 --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -2380,6 +2380,18 @@ genParallelOp(Fortran::lower::AbstractConverter &converter, procBindKindAttr); } +static mlir::omp::SectionOp +genSectionOp(Fortran::lower::AbstractConverter &converter, + Fortran::lower::pft::Evaluation &eval, + mlir::Location currentLocation, + const Fortran::parser::OmpClauseList §ionsClauseList) { + // Currently only private/firstprivate clause is handled, and + // all privatization is done within `omp.section` operations. + return genOpWithBody(converter, eval, currentLocation, + /*outerCombined=*/false, + §ionsClauseList); +} + static mlir::omp::SingleOp genSingleOp(Fortran::lower::AbstractConverter &converter, Fortran::lower::pft::Evaluation &eval, @@ -3382,37 +3394,6 @@ genOMP(Fortran::lower::AbstractConverter &converter, genNestedEvaluations(converter, eval); } -static void -genOMP(Fortran::lower::AbstractConverter &converter, - Fortran::lower::SymMap &symTable, - Fortran::semantics::SemanticsContext &semanticsContext, - Fortran::lower::pft::Evaluation &eval, - const Fortran::parser::OpenMPSectionConstruct §ionConstruct) { - mlir::Location currentLocation = converter.getCurrentLocation(); - const Fortran::parser::OpenMPConstruct *parentOmpConstruct = - eval.parentConstruct->getIf(); - assert(parentOmpConstruct && - "No enclosing parent OpenMPConstruct on SECTION construct"); - const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct = - std::get_if( - &parentOmpConstruct->u); - assert(sectionsConstruct && "SECTION construct must have parent" - "SECTIONS construct"); - const Fortran::parser::OmpClauseList §ionsClauseList = - std::get( - std::get( - sectionsConstruct->t) - .t); - // Currently only private/firstprivate clause is handled, and - // all privatization is done within `omp.section` operations. - symTable.pushScope(); - genOpWithBody(converter, eval, currentLocation, - /*outerCombined=*/false, - §ionsClauseList); - genNestedEvaluations(converter, eval); - symTable.popScope(); -} - static void genOMP(Fortran::lower::AbstractConverter &converter, Fortran::lower::SymMap &symTable, @@ -3458,7 +3439,18 @@ genOMP(Fortran::lower::AbstractConverter &converter, /*reductions=*/nullptr, allocateOperands, allocatorOperands, nowaitClauseOperand); - genNestedEvaluations(converter, eval); + const auto §ionBlocks = + std::get(sectionsConstruct.t); + auto &firOpBuilder = converter.getFirOpBuilder(); + auto ip = firOpBuilder.saveInsertionPoint(); + for (const auto &[nblock, neval] : + llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) { + symTable.pushScope(); + genSectionOp(converter, neval, currentLocation, sectionsClauseList); + genNestedEvaluations(converter, neval); + symTable.popScope(); + firOpBuilder.restoreInsertionPoint(ip); + } } static void @@ -3578,8 +3570,8 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, sectionsConstruct); }, [&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) { - genOMP(converter, symTable, semanticsContext, eval, - sectionConstruct); + // SECTION constructs are handled as a part of SECTIONS. + llvm_unreachable("Unexpected standalone OMP SECTION"); }, [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) { genOMP(converter, symTable, semanticsContext, eval, loopConstruct);