Skip to content

Commit 7caeec5

Browse files
authored
[NFC][flang][OpenMP] Unify genSectionsOp's prototype to match other genXXXOp functions (#144013)
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 30350af commit 7caeec5

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 12 additions & 23 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,
@@ -3458,10 +3464,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
34583464
// Lowered in the enclosing genSectionsOp.
34593465
break;
34603466
case llvm::omp::Directive::OMPD_sections:
3461-
// Called directly from genOMP([...], OpenMPSectionsConstruct) because it
3462-
// has a different prototype.
3463-
// This code path is still taken when iterating through the construct queue
3464-
// in genBodyOfOp
3467+
genSectionsOp(converter, symTable, semaCtx, eval, loc, queue, item);
34653468
break;
34663469
case llvm::omp::Directive::OMPD_simd:
34673470
newOp =
@@ -4137,8 +4140,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
41374140
std::get<parser::OmpClauseList>(beginSectionsDirective.t), semaCtx);
41384141
const auto &endSectionsDirective =
41394142
std::get<parser::OmpEndSectionsDirective>(sectionsConstruct.t);
4140-
const auto &sectionBlocks =
4141-
std::get<parser::OmpSectionBlocks>(sectionsConstruct.t);
41424143
clauses.append(makeClauses(
41434144
std::get<parser::OmpClauseList>(endSectionsDirective.t), semaCtx));
41444145
mlir::Location currentLocation = converter.getCurrentLocation();
@@ -4150,22 +4151,10 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
41504151
ConstructQueue queue{
41514152
buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx,
41524153
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-
}
41614154

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());
4155+
sectionsStack.push_back(&sectionsConstruct);
4156+
genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
4157+
queue.begin());
41694158
}
41704159

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

0 commit comments

Comments
 (0)