Skip to content

Commit 22f6e97

Browse files
authored
[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]
1 parent 219c14a commit 22f6e97

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,18 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
23802380
procBindKindAttr);
23812381
}
23822382

2383+
static mlir::omp::SectionOp
2384+
genSectionOp(Fortran::lower::AbstractConverter &converter,
2385+
Fortran::lower::pft::Evaluation &eval,
2386+
mlir::Location currentLocation,
2387+
const Fortran::parser::OmpClauseList &sectionsClauseList) {
2388+
// Currently only private/firstprivate clause is handled, and
2389+
// all privatization is done within `omp.section` operations.
2390+
return genOpWithBody<mlir::omp::SectionOp>(converter, eval, currentLocation,
2391+
/*outerCombined=*/false,
2392+
&sectionsClauseList);
2393+
}
2394+
23832395
static mlir::omp::SingleOp
23842396
genSingleOp(Fortran::lower::AbstractConverter &converter,
23852397
Fortran::lower::pft::Evaluation &eval,
@@ -3382,37 +3394,6 @@ genOMP(Fortran::lower::AbstractConverter &converter,
33823394
genNestedEvaluations(converter, eval);
33833395
}
33843396

3385-
static void
3386-
genOMP(Fortran::lower::AbstractConverter &converter,
3387-
Fortran::lower::SymMap &symTable,
3388-
Fortran::semantics::SemanticsContext &semanticsContext,
3389-
Fortran::lower::pft::Evaluation &eval,
3390-
const Fortran::parser::OpenMPSectionConstruct &sectionConstruct) {
3391-
mlir::Location currentLocation = converter.getCurrentLocation();
3392-
const Fortran::parser::OpenMPConstruct *parentOmpConstruct =
3393-
eval.parentConstruct->getIf<Fortran::parser::OpenMPConstruct>();
3394-
assert(parentOmpConstruct &&
3395-
"No enclosing parent OpenMPConstruct on SECTION construct");
3396-
const Fortran::parser::OpenMPSectionsConstruct *sectionsConstruct =
3397-
std::get_if<Fortran::parser::OpenMPSectionsConstruct>(
3398-
&parentOmpConstruct->u);
3399-
assert(sectionsConstruct && "SECTION construct must have parent"
3400-
"SECTIONS construct");
3401-
const Fortran::parser::OmpClauseList &sectionsClauseList =
3402-
std::get<Fortran::parser::OmpClauseList>(
3403-
std::get<Fortran::parser::OmpBeginSectionsDirective>(
3404-
sectionsConstruct->t)
3405-
.t);
3406-
// Currently only private/firstprivate clause is handled, and
3407-
// all privatization is done within `omp.section` operations.
3408-
symTable.pushScope();
3409-
genOpWithBody<mlir::omp::SectionOp>(converter, eval, currentLocation,
3410-
/*outerCombined=*/false,
3411-
&sectionsClauseList);
3412-
genNestedEvaluations(converter, eval);
3413-
symTable.popScope();
3414-
}
3415-
34163397
static void
34173398
genOMP(Fortran::lower::AbstractConverter &converter,
34183399
Fortran::lower::SymMap &symTable,
@@ -3458,7 +3439,18 @@ genOMP(Fortran::lower::AbstractConverter &converter,
34583439
/*reductions=*/nullptr, allocateOperands,
34593440
allocatorOperands, nowaitClauseOperand);
34603441

3461-
genNestedEvaluations(converter, eval);
3442+
const auto &sectionBlocks =
3443+
std::get<Fortran::parser::OmpSectionBlocks>(sectionsConstruct.t);
3444+
auto &firOpBuilder = converter.getFirOpBuilder();
3445+
auto ip = firOpBuilder.saveInsertionPoint();
3446+
for (const auto &[nblock, neval] :
3447+
llvm::zip(sectionBlocks.v, eval.getNestedEvaluations())) {
3448+
symTable.pushScope();
3449+
genSectionOp(converter, neval, currentLocation, sectionsClauseList);
3450+
genNestedEvaluations(converter, neval);
3451+
symTable.popScope();
3452+
firOpBuilder.restoreInsertionPoint(ip);
3453+
}
34623454
}
34633455

34643456
static void
@@ -3578,8 +3570,8 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
35783570
sectionsConstruct);
35793571
},
35803572
[&](const Fortran::parser::OpenMPSectionConstruct &sectionConstruct) {
3581-
genOMP(converter, symTable, semanticsContext, eval,
3582-
sectionConstruct);
3573+
// SECTION constructs are handled as a part of SECTIONS.
3574+
llvm_unreachable("Unexpected standalone OMP SECTION");
35833575
},
35843576
[&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
35853577
genOMP(converter, symTable, semanticsContext, eval, loopConstruct);

0 commit comments

Comments
 (0)