Skip to content

Commit 1769def

Browse files
skatrakjoaosaffran
authored and
joaosaffran
committed
[Flang][OpenMP] Update semantics checks for 'teams' nesting (llvm#126922)
This patch introduces a directive set for combined constructs where `teams` is the last leaf. This is used in a couple places to simplify checks, which is NFC, but it also replaces two incorrect uses of `topTeamsSet`. Before, these checks would incorrectly skip combined constructs where `teams` was the last leaf construct when checking for allowed nested constructs inside of a `teams` region. Similarly, it would also incorrectly perform these checks whenever a compound `teams` construct where `teams` was the first leaf construct was found.
1 parent 0956b10 commit 1769def

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

flang/include/flang/Semantics/openmp-directive-sets.h

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace llvm::omp {
2121
//===----------------------------------------------------------------------===//
2222
// - top<Directive>Set: The directive appears alone or as the first in a
2323
// compound construct.
24+
// - bottom<Directive>Set: The directive appears alone or as the last in a
25+
// compound construct.
2426
// - all<Directive>Set: All standalone or compound uses of the directive.
2527

2628
static const OmpDirectiveSet topDistributeSet{
@@ -172,6 +174,11 @@ static const OmpDirectiveSet topTeamsSet{
172174
Directive::OMPD_teams_loop,
173175
};
174176

177+
static const OmpDirectiveSet bottomTeamsSet{
178+
Directive::OMPD_target_teams,
179+
Directive::OMPD_teams,
180+
};
181+
175182
static const OmpDirectiveSet allTeamsSet{
176183
OmpDirectiveSet{
177184
Directive::OMPD_target_teams,

flang/lib/Semantics/check-omp-structure.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,7 @@ void OmpStructureChecker::HasInvalidDistributeNesting(
487487
violation = true;
488488
} else {
489489
// `distribute` region has to be strictly nested inside `teams`
490-
if (!OmpDirectiveSet{llvm::omp::OMPD_teams, llvm::omp::OMPD_target_teams}
491-
.test(GetContextParent().directive)) {
490+
if (!llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
492491
violation = true;
493492
}
494493
}
@@ -518,8 +517,7 @@ void OmpStructureChecker::HasInvalidLoopBinding(
518517

519518
if (llvm::omp::Directive::OMPD_loop == beginDir.v &&
520519
CurrentDirectiveIsNested() &&
521-
OmpDirectiveSet{llvm::omp::OMPD_teams, llvm::omp::OMPD_target_teams}.test(
522-
GetContextParent().directive)) {
520+
llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
523521
teamsBindingChecker(
524522
"`BIND(TEAMS)` must be specified since the `LOOP` region is "
525523
"strictly nested inside a `TEAMS` region."_err_en_US);
@@ -726,7 +724,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
726724
HasInvalidDistributeNesting(x);
727725
HasInvalidLoopBinding(x);
728726
if (CurrentDirectiveIsNested() &&
729-
llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
727+
llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
730728
HasInvalidTeamsNesting(beginDir.v, beginDir.source);
731729
}
732730
if ((beginDir.v == llvm::omp::Directive::OMPD_distribute_parallel_do_simd) ||
@@ -1169,7 +1167,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
11691167
}
11701168

11711169
if (CurrentDirectiveIsNested()) {
1172-
if (llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
1170+
if (llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
11731171
HasInvalidTeamsNesting(beginDir.v, beginDir.source);
11741172
}
11751173
if (GetContext().directive == llvm::omp::Directive::OMPD_master) {

flang/test/Semantics/OpenMP/nested-target.f90

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ program main
5454
n2 = 10
5555
!$omp target teams map(to:a)
5656
!PORTABILITY: If TARGET DATA directive is nested inside TARGET region, the behaviour is unspecified
57+
!ERROR: Only `DISTRIBUTE`, `PARALLEL`, or `LOOP` regions are allowed to be strictly nested inside `TEAMS` region.
5758
!$omp target data map(n1,n2)
5859
do i=1, n1
5960
do j=1, n2
@@ -65,6 +66,7 @@ program main
6566

6667
!$omp target teams map(to:a) map(from:n1,n2)
6768
!PORTABILITY: If TARGET TEAMS DISTRIBUTE PARALLEL DO directive is nested inside TARGET region, the behaviour is unspecified
69+
!ERROR: Only `DISTRIBUTE`, `PARALLEL`, or `LOOP` regions are allowed to be strictly nested inside `TEAMS` region.
6870
!$omp target teams distribute parallel do
6971
do i=1, n1
7072
do j=1, n2

flang/test/Semantics/OpenMP/nested-teams.f90

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ program main
6868
!$omp end target
6969

7070
!$omp target teams
71+
!ERROR: Only `DISTRIBUTE`, `PARALLEL`, or `LOOP` regions are allowed to be strictly nested inside `TEAMS` region.
7172
!ERROR: TEAMS region can only be strictly nested within the implicit parallel region or TARGET region
7273
!$omp teams
7374
a = 3.14

0 commit comments

Comments
 (0)