Skip to content

Commit 9448844

Browse files
authored
[flang][MLIR] Support delayed privatization for wsloop (PFT -> MLIR) (#118271)
Adds PFT to MLIR lowering for delayed privatization of `omp.wsloop` ops. Lowering to LLVM IR will be added in a later PR.
1 parent 2474cf7 commit 9448844

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,19 +2042,19 @@ static void genStandaloneDo(lower::AbstractConverter &converter,
20422042
genWsloopClauses(converter, semaCtx, stmtCtx, item->clauses, loc,
20432043
wsloopClauseOps, wsloopReductionSyms);
20442044

2045-
// TODO: Support delayed privatization.
20462045
DataSharingProcessor dsp(converter, semaCtx, item->clauses, eval,
20472046
/*shouldCollectPreDeterminedSymbols=*/true,
2048-
/*useDelayedPrivatization=*/false, &symTable);
2049-
dsp.processStep1();
2047+
enableDelayedPrivatizationStaging, &symTable);
2048+
dsp.processStep1(&wsloopClauseOps);
20502049

20512050
mlir::omp::LoopNestOperands loopNestClauseOps;
20522051
llvm::SmallVector<const semantics::Symbol *> iv;
20532052
genLoopNestClauses(converter, semaCtx, eval, item->clauses, loc,
20542053
loopNestClauseOps, iv);
20552054

20562055
EntryBlockArgs wsloopArgs;
2057-
// TODO: Add private syms and vars.
2056+
wsloopArgs.priv.syms = dsp.getDelayedPrivSymbols();
2057+
wsloopArgs.priv.vars = wsloopClauseOps.privateVars;
20582058
wsloopArgs.reduction.syms = wsloopReductionSyms;
20592059
wsloopArgs.reduction.vars = wsloopClauseOps.reductionVars;
20602060
auto wsloopOp = genWrapperOp<mlir::omp::WsloopOp>(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization-staging \
2+
! RUN: -o - %s 2>&1 | FileCheck %s
3+
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization-staging -o - %s 2>&1 \
4+
! RUN: | FileCheck %s
5+
6+
subroutine wsloop_private
7+
implicit none
8+
integer :: x, i
9+
10+
!$omp parallel do firstprivate(x)
11+
do i = 0, 10
12+
x = x + i
13+
end do
14+
end subroutine wsloop_private
15+
16+
! CHECK: omp.private {type = private} @[[I_PRIVATIZER:.*i_private_ref_i32]]
17+
! CHECK: omp.private {type = firstprivate} @[[X_PRIVATIZER:.*x_firstprivate_ref_i32]]
18+
19+
! CHECK: func.func @{{.*}}() {
20+
! CHECK: %[[I_DECL:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "{{.*}}i"}
21+
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "{{.*}}x"}
22+
23+
! CHECK: omp.parallel {
24+
! CHECK: omp.wsloop private(
25+
! CHECK-SAME: @[[X_PRIVATIZER]] %[[X_DECL]]#0 -> %[[X_ARG:[^[:space:]]+]],
26+
! CHECK-SAME: @[[I_PRIVATIZER]] %[[I_DECL]]#0 -> %[[I_ARG:.*]] : {{.*}}) {
27+
28+
! CHECK: omp.loop_nest (%[[IV:.*]]) : i32 = {{.*}} {
29+
! CHECK: %[[X_PRIV_DECL:.*]]:2 = hlfir.declare %[[X_ARG]] {uniq_name = "{{.*}}x"}
30+
! CHECK: %[[I_PRIV_DECL:.*]]:2 = hlfir.declare %[[I_ARG]] {uniq_name = "{{.*}}i"}
31+
! CHECK: fir.store %[[IV]] to %[[I_PRIV_DECL]]#1
32+
! CHECK: %[[X_VAL:.*]] = fir.load %[[X_PRIV_DECL]]#0
33+
! CHECK: %[[I_VAL:.*]] = fir.load %[[I_PRIV_DECL]]#0
34+
! CHECK: %[[ADD_VAL:.*]] = arith.addi %[[X_VAL]], %[[I_VAL]]
35+
! CHECK: hlfir.assign %[[ADD_VAL]] to %[[X_PRIV_DECL]]#0
36+
! CHECK: omp.yield
37+
! CHECK: }
38+
! CHECK: }
39+
40+
! CHECK: omp.terminator
41+
! CHECK: }
42+
! CHECK: }

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,8 +2066,8 @@ void WsloopOp::build(OpBuilder &builder, OperationState &state,
20662066
builder, state,
20672067
/*allocate_vars=*/{}, /*allocator_vars=*/{}, clauses.linearVars,
20682068
clauses.linearStepVars, clauses.nowait, clauses.order, clauses.orderMod,
2069-
clauses.ordered, /*private_vars=*/{}, /*private_syms=*/nullptr,
2070-
clauses.reductionVars,
2069+
clauses.ordered, clauses.privateVars,
2070+
makeArrayAttr(ctx, clauses.privateSyms), clauses.reductionVars,
20712071
makeDenseBoolArrayAttr(ctx, clauses.reductionByref),
20722072
makeArrayAttr(ctx, clauses.reductionSyms), clauses.scheduleKind,
20732073
clauses.scheduleChunk, clauses.scheduleMod, clauses.scheduleSimd);

0 commit comments

Comments
 (0)