Skip to content

Commit 67ea0e5

Browse files
committed
[Flang][OpenMP] Handle SECTION construct from within SECTIONS
Introduce `createSectionOp`, invoke it from the SECTIONS construct for each nested SECTION construct. This makes it unnecessary to embed OpenMPSectionConstruct inside of OpenMPSectionConstruct anymore. Recursive lowering [3/5]
1 parent 841ae5f commit 67ea0e5

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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 &sectionsClauseList) {
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+
&sectionsClauseList);
2392+
}
2393+
23822394
static mlir::omp::SingleOp
23832395
genSingleOp(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 &sectionConstruct) {
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 &sectionsClauseList =
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-
&sectionsClauseList);
3403-
genNestedEvaluations(converter, eval);
3404-
symTable.popScope();
3405-
}
3406-
34073390
static void
34083391
genOMP(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 &sectionBlocks =
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

34533447
static void
@@ -3562,7 +3556,8 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
35623556
genOMP(converter, symTable, eval, sectionsConstruct);
35633557
},
35643558
[&](const Fortran::parser::OpenMPSectionConstruct &sectionConstruct) {
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

Comments
 (0)