diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 82673f0948a5b..060eba1b906e3 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -201,6 +201,8 @@ class HostEvalInfo { /// structures, but it will probably still require some further work to support /// reverse offloading. static llvm::SmallVector hostEvalInfo; +static llvm::SmallVector + sectionsStack; /// Bind symbols to their corresponding entry block arguments. /// @@ -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 §ionBlocks) { + const ConstructQueue &queue, + ConstructQueue::const_iterator item) { + assert(!sectionsStack.empty()); + const auto §ionBlocks = + std::get(sectionsStack.back()->t); + sectionsStack.pop_back(); mlir::omp::SectionsOperands clauseOps; llvm::SmallVector reductionSyms; genSectionsClauses(converter, semaCtx, item->clauses, loc, clauseOps, @@ -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 = @@ -4137,8 +4140,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable, std::get(beginSectionsDirective.t), semaCtx); const auto &endSectionsDirective = std::get(sectionsConstruct.t); - const auto §ionBlocks = - std::get(sectionsConstruct.t); clauses.append(makeClauses( std::get(endSectionsDirective.t), semaCtx)); mlir::Location currentLocation = converter.getCurrentLocation(); @@ -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(§ionsConstruct); + genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue, + queue.begin()); } static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,