Skip to content

Commit

Permalink
[Flang][OpenMP] Handle SECTION construct from within SECTIONS (#77759)
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
kparzysz committed Jan 15, 2024
1 parent 219c14a commit 22f6e97
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions flang/lib/Lower/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &sectionsClauseList) {
// 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,
&sectionsClauseList);
}

static mlir::omp::SingleOp
genSingleOp(Fortran::lower::AbstractConverter &converter,
Fortran::lower::pft::Evaluation &eval,
Expand Down Expand Up @@ -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 &sectionConstruct) {
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 &sectionsClauseList =
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,
&sectionsClauseList);
genNestedEvaluations(converter, eval);
symTable.popScope();
}

static void
genOMP(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symTable,
Expand Down Expand Up @@ -3458,7 +3439,18 @@ genOMP(Fortran::lower::AbstractConverter &converter,
/*reductions=*/nullptr, allocateOperands,
allocatorOperands, nowaitClauseOperand);

genNestedEvaluations(converter, eval);
const auto &sectionBlocks =
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
Expand Down Expand Up @@ -3578,8 +3570,8 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
sectionsConstruct);
},
[&](const Fortran::parser::OpenMPSectionConstruct &sectionConstruct) {
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);
Expand Down

0 comments on commit 22f6e97

Please sign in to comment.