[flang-commits] [flang] [flang][OpenMP] Add TODOs for target [teams|parallel] private (PR #143706)
Kareem Ergawy via flang-commits
flang-commits at lists.llvm.org
Thu Jun 12 06:06:23 PDT 2025
ergawy wrote:
Not the best solution but there is a precedent for using a global to handle cross-construct communication:
```diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index c13fa471978d..d14464f0e854 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -201,6 +201,8 @@ private:
/// 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.
///
@@ -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<parser::OmpSectionBlocks>(sectionsStack.back()->t);
+ sectionsStack.pop_back();
mlir::omp::SectionsOperands clauseOps;
llvm::SmallVector<const semantics::Symbol *> reductionSyms;
genSectionsClauses(converter, semaCtx, item->clauses, loc, clauseOps,
@@ -2668,6 +2674,7 @@ genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
mlir::Location loc, const ConstructQueue &queue,
ConstructQueue::const_iterator item) {
+ lower::SymMapScope scope(symTable);
mlir::omp::TeamsOperands clauseOps;
llvm::SmallVector<const semantics::Symbol *> reductionSyms;
genTeamsClauses(converter, semaCtx, stmtCtx, item->clauses, loc, clauseOps,
@@ -2975,6 +2982,7 @@ static mlir::omp::ParallelOp genStandaloneParallel(
lower::StatementContext &stmtCtx, semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval, mlir::Location loc,
const ConstructQueue &queue, ConstructQueue::const_iterator item) {
+ lower::SymMapScope scope(symTable);
mlir::omp::ParallelOperands parallelClauseOps;
llvm::SmallVector<const semantics::Symbol *> parallelReductionSyms;
genParallelClauses(converter, semaCtx, stmtCtx, item->clauses, loc,
@@ -3462,6 +3470,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
// 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 =
@@ -4143,22 +4152,9 @@ 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,
```
This passes all lit tests and also handles the `target [parallel|teams] private(...)` cases.
https://github.com/llvm/llvm-project/pull/143706
More information about the flang-commits
mailing list