Skip to content

[NFC][flang][OpenMP] Unify genSectionsOp's prototype to match other genXXXOp functions #144013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ class HostEvalInfo {
/// structures, but it will probably still require some further work to support
/// reverse offloading.
static llvm::SmallVector<HostEvalInfo, 0> hostEvalInfo;
static llvm::SmallVector<const parser::OpenMPSectionsConstruct *, 0>
sectionsStack;

/// Bind symbols to their corresponding entry block arguments.
///
Expand Down Expand Up @@ -2220,8 +2222,12 @@ static mlir::omp::SectionsOp
genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval, mlir::Location loc,
const ConstructQueue &queue, ConstructQueue::const_iterator item,
const parser::OmpSectionBlocks &sectionBlocks) {
const ConstructQueue &queue,
ConstructQueue::const_iterator item) {
assert(!sectionsStack.empty());
const auto &sectionBlocks =
std::get<parser::OmpSectionBlocks>(sectionsStack.back()->t);
sectionsStack.pop_back();
Comment on lines +2229 to +2230
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::get<parser::OmpSectionBlocks>(sectionsStack.back()->t);
sectionsStack.pop_back();
std::get<parser::OmpSectionBlocks>(sectionsStack.pop_back_val()->t);

mlir::omp::SectionsOperands clauseOps;
llvm::SmallVector<const semantics::Symbol *> reductionSyms;
genSectionsClauses(converter, semaCtx, item->clauses, loc, clauseOps,
Expand Down Expand Up @@ -3458,10 +3464,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
// Lowered in the enclosing genSectionsOp.
break;
case llvm::omp::Directive::OMPD_sections:
// Called directly from genOMP([...], OpenMPSectionsConstruct) because it
// has a different prototype.
// This code path is still taken when iterating through the construct queue
// in genBodyOfOp
genSectionsOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_simd:
newOp =
Expand Down Expand Up @@ -4137,8 +4140,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
std::get<parser::OmpClauseList>(beginSectionsDirective.t), semaCtx);
const auto &endSectionsDirective =
std::get<parser::OmpEndSectionsDirective>(sectionsConstruct.t);
const auto &sectionBlocks =
std::get<parser::OmpSectionBlocks>(sectionsConstruct.t);
clauses.append(makeClauses(
std::get<parser::OmpClauseList>(endSectionsDirective.t), semaCtx));
mlir::Location currentLocation = converter.getCurrentLocation();
Expand All @@ -4150,22 +4151,10 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
ConstructQueue queue{
buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx,
eval, source, directive, clauses)};
ConstructQueue::iterator next = queue.begin();
// Generate constructs that come first e.g. Parallel
while (next != queue.end() &&
next->id != llvm::omp::Directive::OMPD_sections) {
genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
next);
next = std::next(next);
}

// call genSectionsOp directly (not via genOMPDispatch) so that we can add the
// sectionBlocks argument
assert(next != queue.end());
assert(next->id == llvm::omp::Directive::OMPD_sections);
genSectionsOp(converter, symTable, semaCtx, eval, currentLocation, queue,
next, sectionBlocks);
assert(std::next(next) == queue.end());
sectionsStack.push_back(&sectionsConstruct);
genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
queue.begin());
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
Expand Down
Loading