Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang][OpenMP] Update semantics checks for 'teams' nesting #126922

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions flang/include/flang/Semantics/openmp-directive-sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace llvm::omp {
//===----------------------------------------------------------------------===//
// - top<Directive>Set: The directive appears alone or as the first in a
// compound construct.
// - bottom<Directive>Set: The directive appears alone or as the last in a
// compound construct.
// - all<Directive>Set: All standalone or compound uses of the directive.

static const OmpDirectiveSet topDistributeSet{
Expand Down Expand Up @@ -172,6 +174,11 @@ static const OmpDirectiveSet topTeamsSet{
Directive::OMPD_teams_loop,
};

static const OmpDirectiveSet bottomTeamsSet{
Directive::OMPD_target_teams,
Directive::OMPD_teams,
};

static const OmpDirectiveSet allTeamsSet{
OmpDirectiveSet{
Directive::OMPD_target_teams,
Expand Down
10 changes: 4 additions & 6 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ void OmpStructureChecker::HasInvalidDistributeNesting(
violation = true;
} else {
// `distribute` region has to be strictly nested inside `teams`
if (!OmpDirectiveSet{llvm::omp::OMPD_teams, llvm::omp::OMPD_target_teams}
.test(GetContextParent().directive)) {
if (!llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
violation = true;
}
}
Expand Down Expand Up @@ -518,8 +517,7 @@ void OmpStructureChecker::HasInvalidLoopBinding(

if (llvm::omp::Directive::OMPD_loop == beginDir.v &&
CurrentDirectiveIsNested() &&
OmpDirectiveSet{llvm::omp::OMPD_teams, llvm::omp::OMPD_target_teams}.test(
GetContextParent().directive)) {
llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
teamsBindingChecker(
"`BIND(TEAMS)` must be specified since the `LOOP` region is "
"strictly nested inside a `TEAMS` region."_err_en_US);
Expand Down Expand Up @@ -726,7 +724,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
HasInvalidDistributeNesting(x);
HasInvalidLoopBinding(x);
if (CurrentDirectiveIsNested() &&
llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
HasInvalidTeamsNesting(beginDir.v, beginDir.source);
}
if ((beginDir.v == llvm::omp::Directive::OMPD_distribute_parallel_do_simd) ||
Expand Down Expand Up @@ -1169,7 +1167,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
}

if (CurrentDirectiveIsNested()) {
if (llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
if (llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
HasInvalidTeamsNesting(beginDir.v, beginDir.source);
}
if (GetContext().directive == llvm::omp::Directive::OMPD_master) {
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Semantics/OpenMP/nested-target.f90
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ program main
n2 = 10
!$omp target teams map(to:a)
!PORTABILITY: If TARGET DATA directive is nested inside TARGET region, the behaviour is unspecified
!ERROR: Only `DISTRIBUTE`, `PARALLEL`, or `LOOP` regions are allowed to be strictly nested inside `TEAMS` region.
!$omp target data map(n1,n2)
do i=1, n1
do j=1, n2
Expand All @@ -65,6 +66,7 @@ program main

!$omp target teams map(to:a) map(from:n1,n2)
!PORTABILITY: If TARGET TEAMS DISTRIBUTE PARALLEL DO directive is nested inside TARGET region, the behaviour is unspecified
!ERROR: Only `DISTRIBUTE`, `PARALLEL`, or `LOOP` regions are allowed to be strictly nested inside `TEAMS` region.
!$omp target teams distribute parallel do
do i=1, n1
do j=1, n2
Expand Down
1 change: 1 addition & 0 deletions flang/test/Semantics/OpenMP/nested-teams.f90
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ program main
!$omp end target

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