[flang-commits] [flang] 22f6e97 - [Flang][OpenMP] Handle SECTION construct from within SECTIONS (#77759)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 15 09:24:32 PST 2024
Author: Krzysztof Parzyszek
Date: 2024-01-15T11:24:28-06:00
New Revision: 22f6e97d24f6e7190a447fd60e11e8ea03fd8356
URL: https://github.com/llvm/llvm-project/commit/22f6e97d24f6e7190a447fd60e11e8ea03fd8356
DIFF: https://github.com/llvm/llvm-project/commit/22f6e97d24f6e7190a447fd60e11e8ea03fd8356.diff
LOG: [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]
Added:
Modified:
flang/lib/Lower/OpenMP.cpp
Removed:
################################################################################
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<mlir::omp::SectionOp>(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<Fortran::parser::OpenMPConstruct>();
- assert(parentOmpConstruct &&
- "No enclosing parent OpenMPConstruct on SECTION construct");
- const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct =
- std::get_if<Fortran::parser::OpenMPSectionsConstruct>(
- &parentOmpConstruct->u);
- assert(sectionsConstruct && "SECTION construct must have parent"
- "SECTIONS construct");
- const Fortran::parser::OmpClauseList §ionsClauseList =
- std::get<Fortran::parser::OmpClauseList>(
- std::get<Fortran::parser::OmpBeginSectionsDirective>(
- sectionsConstruct->t)
- .t);
- // Currently only private/firstprivate clause is handled, and
- // all privatization is done within `omp.section` operations.
- symTable.pushScope();
- genOpWithBody<mlir::omp::SectionOp>(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<Fortran::parser::OmpSectionBlocks>(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);
More information about the flang-commits
mailing list