Skip to content

Commit 781c76a

Browse files
committed
[NFC][flang][OpenMP] Unify genSectionsOp's prototype to match other genXXXOp functions
Unifies the prototype of `genSectionsOp` to match other ops generators. Doing so, we are able to call `genSectionsOp` directtly from `genOMPDispatch` instead of the special handling needed now to pass the section blocks. This is useful because now we can handle symbol mapping scopes easier for nested OpenMP directives. See #143706 (comment) and the following discussion for more info.
1 parent 4268360 commit 781c76a

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ class HostEvalInfo {
201201
/// structures, but it will probably still require some further work to support
202202
/// reverse offloading.
203203
static llvm::SmallVector<HostEvalInfo, 0> hostEvalInfo;
204+
static llvm::SmallVector<const parser::OpenMPSectionsConstruct *, 0>
205+
sectionsStack;
204206

205207
/// Bind symbols to their corresponding entry block arguments.
206208
///
@@ -2220,8 +2222,12 @@ static mlir::omp::SectionsOp
22202222
genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
22212223
semantics::SemanticsContext &semaCtx,
22222224
lower::pft::Evaluation &eval, mlir::Location loc,
2223-
const ConstructQueue &queue, ConstructQueue::const_iterator item,
2224-
const parser::OmpSectionBlocks &sectionBlocks) {
2225+
const ConstructQueue &queue,
2226+
ConstructQueue::const_iterator item) {
2227+
assert(!sectionsStack.empty());
2228+
const auto &sectionBlocks =
2229+
std::get<parser::OmpSectionBlocks>(sectionsStack.back()->t);
2230+
sectionsStack.pop_back();
22252231
mlir::omp::SectionsOperands clauseOps;
22262232
llvm::SmallVector<const semantics::Symbol *> reductionSyms;
22272233
genSectionsClauses(converter, semaCtx, item->clauses, loc, clauseOps,
@@ -3462,6 +3468,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
34623468
// has a different prototype.
34633469
// This code path is still taken when iterating through the construct queue
34643470
// in genBodyOfOp
3471+
genSectionsOp(converter, symTable, semaCtx, eval, loc, queue, item);
34653472
break;
34663473
case llvm::omp::Directive::OMPD_simd:
34673474
newOp =
@@ -4137,8 +4144,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
41374144
std::get<parser::OmpClauseList>(beginSectionsDirective.t), semaCtx);
41384145
const auto &endSectionsDirective =
41394146
std::get<parser::OmpEndSectionsDirective>(sectionsConstruct.t);
4140-
const auto &sectionBlocks =
4141-
std::get<parser::OmpSectionBlocks>(sectionsConstruct.t);
41424147
clauses.append(makeClauses(
41434148
std::get<parser::OmpClauseList>(endSectionsDirective.t), semaCtx));
41444149
mlir::Location currentLocation = converter.getCurrentLocation();
@@ -4150,22 +4155,10 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
41504155
ConstructQueue queue{
41514156
buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx,
41524157
eval, source, directive, clauses)};
4153-
ConstructQueue::iterator next = queue.begin();
4154-
// Generate constructs that come first e.g. Parallel
4155-
while (next != queue.end() &&
4156-
next->id != llvm::omp::Directive::OMPD_sections) {
4157-
genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
4158-
next);
4159-
next = std::next(next);
4160-
}
41614158

4162-
// call genSectionsOp directly (not via genOMPDispatch) so that we can add the
4163-
// sectionBlocks argument
4164-
assert(next != queue.end());
4165-
assert(next->id == llvm::omp::Directive::OMPD_sections);
4166-
genSectionsOp(converter, symTable, semaCtx, eval, currentLocation, queue,
4167-
next, sectionBlocks);
4168-
assert(std::next(next) == queue.end());
4159+
sectionsStack.push_back(&sectionsConstruct);
4160+
genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
4161+
queue.begin());
41694162
}
41704163

41714164
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,

0 commit comments

Comments
 (0)