[flang-commits] [flang] [flang][OpenMP] Move privatizations out of sections (PR #88191)
Leandro Lupori via flang-commits
flang-commits at lists.llvm.org
Wed Apr 10 07:16:48 PDT 2024
================
@@ -1983,30 +1980,68 @@ genOMP(Fortran::lower::AbstractConverter &converter,
std::get<Fortran::parser::OmpEndSectionsDirective>(sectionsConstruct.t);
const auto &endSectionsClauseList =
std::get<Fortran::parser::OmpClauseList>(endSectionsDirective.t);
- ClauseProcessor(converter, semaCtx, endSectionsClauseList)
- .processNowait(nowaitClauseOperand);
+ hasNowait = ClauseProcessor(converter, semaCtx, endSectionsClauseList)
+ .processNowait(nowaitClauseOperand);
}
+ // Insert privatizations before SECTIONS
+ symTable.pushScope();
+ DataSharingProcessor dsp(converter, semaCtx, sectionsClauseList, eval);
+ dsp.processStep1();
+
// SECTIONS construct
- genOpWithBody<mlir::omp::SectionsOp>(
+ auto sectionsOp = genOpWithBody<mlir::omp::SectionsOp>(
OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(false),
/*reduction_vars=*/mlir::ValueRange(),
/*reductions=*/nullptr, allocateOperands, allocatorOperands,
nowaitClauseOperand);
+ std::optional<Clause> lastPrivateClause;
+ for (const Fortran::parser::OmpClause &clause : sectionsClauseList.v) {
+ if (std::holds_alternative<Fortran::parser::OmpClause::Lastprivate>(
+ clause.u)) {
+ lastPrivateClause = makeClause(clause, semaCtx);
+ }
+ }
+
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, semaCtx, neval, /*genNested=*/true, currentLocation,
- sectionsClauseList);
- symTable.popScope();
+ auto zippy = llvm::zip(sectionBlocks.v, eval.getNestedEvaluations());
+ auto it = zippy.begin(), next = it, end = zippy.end();
+ ++next;
+ for (; it != end; it = next, ++next) {
+ const auto &[nblock, neval] = *it;
+ mlir::omp::SectionOp sectionOp = genSectionOp(
+ converter, semaCtx, neval, /*genNested=*/true, currentLocation);
+ // For `omp.sections`, lastprivatized variables occur in
+ // lexically final `omp.section` operation.
+ if (next == end && lastPrivateClause) {
----------------
luporl wrote:
Done in last commit.
https://github.com/llvm/llvm-project/pull/88191
More information about the flang-commits
mailing list