[llvm-branch-commits] [flang] [Flang][OpenMP] NFC: Share DataSharingProcessor creation logic for all loop directives (PR #97565)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jul 3 05:17:04 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Sergio Afonso (skatrak)
<details>
<summary>Changes</summary>
This patch moves the logic associated with the creation of a `DataSharingProcessor` instance for loop-associated OpenMP leaf constructs to the `genOMPDispatch` function, avoiding code duplication for standalone and composite loop constructs.
This also prevents privatization-related allocations to be later made inside of loop wrappers when support for composite constructs is implemented.
---
Full diff: https://github.com/llvm/llvm-project/pull/97565.diff
1 Files Affected:
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+48-46)
``````````diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 0d456dde630e2..11b8b957330c8 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1340,12 +1340,9 @@ static mlir::omp::DistributeOp
genDistributeOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval, mlir::Location loc,
- const ConstructQueue &queue, ConstructQueue::iterator item) {
+ const ConstructQueue &queue, ConstructQueue::iterator item,
+ DataSharingProcessor &dsp) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
- symTable.pushScope();
- DataSharingProcessor dsp(converter, semaCtx, item->clauses, eval,
- lower::omp::isLastItemInQueue(item, queue));
- dsp.processStep1();
lower::StatementContext stmtCtx;
mlir::omp::LoopNestClauseOps loopClauseOps;
@@ -1383,7 +1380,6 @@ genDistributeOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
.setGenRegionEntryCb(ivCallback),
queue, item);
- symTable.popScope();
return distributeOp;
}
@@ -1611,12 +1607,8 @@ static mlir::omp::SimdOp
genSimdOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
mlir::Location loc, const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+ ConstructQueue::iterator item, DataSharingProcessor &dsp) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
- symTable.pushScope();
- DataSharingProcessor dsp(converter, semaCtx, item->clauses, eval,
- lower::omp::isLastItemInQueue(item, queue));
- dsp.processStep1();
lower::StatementContext stmtCtx;
mlir::omp::LoopNestClauseOps loopClauseOps;
@@ -1653,7 +1645,6 @@ genSimdOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
.setGenRegionEntryCb(ivCallback),
queue, item);
- symTable.popScope();
return simdOp;
}
@@ -1892,7 +1883,8 @@ static mlir::omp::TaskloopOp
genTaskloopOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval, mlir::Location loc,
- const ConstructQueue &queue, ConstructQueue::iterator item) {
+ const ConstructQueue &queue, ConstructQueue::iterator item,
+ DataSharingProcessor &dsp) {
TODO(loc, "Taskloop construct");
}
@@ -1936,12 +1928,8 @@ static mlir::omp::WsloopOp
genWsloopOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
mlir::Location loc, const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+ ConstructQueue::iterator item, DataSharingProcessor &dsp) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
- symTable.pushScope();
- DataSharingProcessor dsp(converter, semaCtx, item->clauses, eval,
- lower::omp::isLastItemInQueue(item, queue));
- dsp.processStep1();
lower::StatementContext stmtCtx;
mlir::omp::LoopNestClauseOps loopClauseOps;
@@ -1983,7 +1971,7 @@ genWsloopOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
.setReductions(&reductionSyms, &reductionTypes)
.setGenRegionEntryCb(ivCallback),
queue, item);
- symTable.popScope();
+
return wsloopOp;
}
@@ -1995,7 +1983,7 @@ static void genCompositeDistributeParallelDo(
lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
mlir::Location loc, const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+ ConstructQueue::iterator item, DataSharingProcessor &dsp) {
TODO(loc, "Composite DISTRIBUTE PARALLEL DO");
}
@@ -2003,17 +1991,15 @@ static void genCompositeDistributeParallelDoSimd(
lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
mlir::Location loc, const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+ ConstructQueue::iterator item, DataSharingProcessor &dsp) {
TODO(loc, "Composite DISTRIBUTE PARALLEL DO SIMD");
}
-static void genCompositeDistributeSimd(lower::AbstractConverter &converter,
- lower::SymMap &symTable,
- semantics::SemanticsContext &semaCtx,
- lower::pft::Evaluation &eval,
- mlir::Location loc,
- const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+static void genCompositeDistributeSimd(
+ lower::AbstractConverter &converter, lower::SymMap &symTable,
+ semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
+ mlir::Location loc, const ConstructQueue &queue,
+ ConstructQueue::iterator item, DataSharingProcessor &dsp) {
TODO(loc, "Composite DISTRIBUTE SIMD");
}
@@ -2022,7 +2008,8 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval, mlir::Location loc,
const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+ ConstructQueue::iterator item,
+ DataSharingProcessor &dsp) {
ClauseProcessor cp(converter, semaCtx, item->clauses);
cp.processTODO<clause::Aligned, clause::Allocate, clause::Linear,
clause::Safelen, clause::Simdlen>(loc,
@@ -2035,16 +2022,14 @@ static void genCompositeDoSimd(lower::AbstractConverter &converter,
// When support for vectorization is enabled, then we need to add handling of
// if clause. Currently if clause can be skipped because we always assume
// SIMD length = 1.
- genWsloopOp(converter, symTable, semaCtx, eval, loc, queue, item);
+ genWsloopOp(converter, symTable, semaCtx, eval, loc, queue, item, dsp);
}
-static void genCompositeTaskloopSimd(lower::AbstractConverter &converter,
- lower::SymMap &symTable,
- semantics::SemanticsContext &semaCtx,
- lower::pft::Evaluation &eval,
- mlir::Location loc,
- const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+static void genCompositeTaskloopSimd(
+ lower::AbstractConverter &converter, lower::SymMap &symTable,
+ semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
+ mlir::Location loc, const ConstructQueue &queue,
+ ConstructQueue::iterator item, DataSharingProcessor &dsp) {
TODO(loc, "Composite TASKLOOP SIMD");
}
@@ -2060,15 +2045,27 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
ConstructQueue::iterator item) {
assert(item != queue.end());
+ std::optional<DataSharingProcessor> loopDsp;
+ bool loopLeaf = llvm::omp::getDirectiveAssociation(item->id) ==
+ llvm::omp::Association::Loop;
+ if (loopLeaf) {
+ symTable.pushScope();
+ loopDsp.emplace(converter, semaCtx, item->clauses, eval,
+ /*shouldCollectPreDeterminedSymbols=*/true,
+ enableDelayedPrivatization, &symTable);
+ loopDsp->processStep1();
+ }
+
switch (llvm::omp::Directive dir = item->id) {
case llvm::omp::Directive::OMPD_barrier:
genBarrierOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_distribute:
- genDistributeOp(converter, symTable, semaCtx, eval, loc, queue, item);
+ genDistributeOp(converter, symTable, semaCtx, eval, loc, queue, item,
+ *loopDsp);
break;
case llvm::omp::Directive::OMPD_do:
- genWsloopOp(converter, symTable, semaCtx, eval, loc, queue, item);
+ genWsloopOp(converter, symTable, semaCtx, eval, loc, queue, item, *loopDsp);
break;
case llvm::omp::Directive::OMPD_loop:
case llvm::omp::Directive::OMPD_masked:
@@ -2092,7 +2089,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
genSectionsOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_simd:
- genSimdOp(converter, symTable, semaCtx, eval, loc, queue, item);
+ genSimdOp(converter, symTable, semaCtx, eval, loc, queue, item, *loopDsp);
break;
case llvm::omp::Directive::OMPD_single:
genSingleOp(converter, symTable, semaCtx, eval, loc, queue, item);
@@ -2122,7 +2119,8 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
genTaskgroupOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_taskloop:
- genTaskloopOp(converter, symTable, semaCtx, eval, loc, queue, item);
+ genTaskloopOp(converter, symTable, semaCtx, eval, loc, queue, item,
+ *loopDsp);
break;
case llvm::omp::Directive::OMPD_taskwait:
genTaskwaitOp(converter, symTable, semaCtx, eval, loc, queue, item);
@@ -2148,26 +2146,30 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
// Composite constructs
case llvm::omp::Directive::OMPD_distribute_parallel_do:
genCompositeDistributeParallelDo(converter, symTable, semaCtx, eval, loc,
- queue, item);
+ queue, item, *loopDsp);
break;
case llvm::omp::Directive::OMPD_distribute_parallel_do_simd:
genCompositeDistributeParallelDoSimd(converter, symTable, semaCtx, eval,
- loc, queue, item);
+ loc, queue, item, *loopDsp);
break;
case llvm::omp::Directive::OMPD_distribute_simd:
genCompositeDistributeSimd(converter, symTable, semaCtx, eval, loc, queue,
- item);
+ item, *loopDsp);
break;
case llvm::omp::Directive::OMPD_do_simd:
- genCompositeDoSimd(converter, symTable, semaCtx, eval, loc, queue, item);
+ genCompositeDoSimd(converter, symTable, semaCtx, eval, loc, queue, item,
+ *loopDsp);
break;
case llvm::omp::Directive::OMPD_taskloop_simd:
genCompositeTaskloopSimd(converter, symTable, semaCtx, eval, loc, queue,
- item);
+ item, *loopDsp);
break;
default:
break;
}
+
+ if (loopLeaf)
+ symTable.popScope();
}
//===----------------------------------------------------------------------===//
``````````
</details>
https://github.com/llvm/llvm-project/pull/97565
More information about the llvm-branch-commits
mailing list