Skip to content

Commit 2dc58e0

Browse files
authored
[flang][OpenMP] Add symbol table scopes for teams and parallel (#144015)
Adds symbol map scopes for standalone `teams` and `parallel` constructs. This is required to properly bind the privatized symbols in both constructs so that nested constructs can find them. Resolves #116428.
1 parent b5dbf82 commit 2dc58e0

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,7 @@ genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
26742674
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
26752675
mlir::Location loc, const ConstructQueue &queue,
26762676
ConstructQueue::const_iterator item) {
2677+
lower::SymMapScope scope(symTable);
26772678
mlir::omp::TeamsOperands clauseOps;
26782679
llvm::SmallVector<const semantics::Symbol *> reductionSyms;
26792680
genTeamsClauses(converter, semaCtx, stmtCtx, item->clauses, loc, clauseOps,
@@ -2981,6 +2982,7 @@ static mlir::omp::ParallelOp genStandaloneParallel(
29812982
lower::StatementContext &stmtCtx, semantics::SemanticsContext &semaCtx,
29822983
lower::pft::Evaluation &eval, mlir::Location loc,
29832984
const ConstructQueue &queue, ConstructQueue::const_iterator item) {
2985+
lower::SymMapScope scope(symTable);
29842986
mlir::omp::ParallelOperands parallelClauseOps;
29852987
llvm::SmallVector<const semantics::Symbol *> parallelReductionSyms;
29862988
genParallelClauses(converter, semaCtx, stmtCtx, item->clauses, loc,
@@ -4027,13 +4029,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
40274029
parser::ToUpperCaseLetters(llvm::omp::getOpenMPClauseName(clause.id));
40284030
TODO(clauseLocation, name + " clause is not implemented yet");
40294031
}
4030-
4031-
if (std::holds_alternative<clause::Private>(clause.u) &&
4032-
origDirective == llvm::omp::Directive::OMPD_target_teams)
4033-
TODO(clauseLocation, "TARGET TEAMS PRIVATE is not implemented yet");
4034-
if (std::holds_alternative<clause::Private>(clause.u) &&
4035-
origDirective == llvm::omp::Directive::OMPD_target_parallel)
4036-
TODO(clauseLocation, "TARGET PARALLEL PRIVATE is not implemented yet");
40374032
}
40384033

40394034
llvm::omp::Directive directive =

flang/test/Lower/OpenMP/Todo/target-parallel-private.f90

Lines changed: 0 additions & 13 deletions
This file was deleted.

flang/test/Lower/OpenMP/Todo/target-teams-private.f90

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization \
2+
! RUN: -o - %s 2>&1 | FileCheck %s
3+
! RUN: bbc -emit-hlfir -fopenmp --enable-delayed-privatization -o - %s 2>&1 |\
4+
! RUN: FileCheck %s
5+
6+
!===============================================================================
7+
! `private` clause on `target parallel`
8+
!===============================================================================
9+
10+
subroutine target_parallel_private()
11+
integer, dimension(3) :: i
12+
!$omp target parallel private(i)
13+
!$omp end target parallel
14+
end subroutine
15+
16+
! CHECK: omp.private {type = private} @[[PRIVATIZER:.*]] : {{.*}}
17+
18+
! CHECK: omp.target {{.*}} {
19+
! CHECK: omp.parallel private(@[[PRIVATIZER]] %{{.*}} -> %{{.*}} : {{.*}}) {
20+
! CHECK: }
21+
! CHECK: }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization \
2+
! RUN: -o - %s 2>&1 | FileCheck %s
3+
! RUN: bbc -emit-hlfir -fopenmp --enable-delayed-privatization -o - %s 2>&1 |\
4+
! RUN: FileCheck %s
5+
6+
!===============================================================================
7+
! `private` clause on `target teams`
8+
!===============================================================================
9+
10+
subroutine target_teams_private()
11+
integer, dimension(3) :: i
12+
!$omp target teams private(i)
13+
!$omp end target teams
14+
end subroutine
15+
16+
! CHECK: omp.target {{.*}} {
17+
! CHECK: omp.teams {
18+
! CHECK: %{{.*}} = fir.alloca !fir.array<3xi32> {bindc_name = "i", {{.*}}}
19+
! CHECK: }
20+
! CHECK: }

0 commit comments

Comments
 (0)