Skip to content

[Flang][OpenMP] Add frontend support for directives involving master #113893

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

Merged
merged 2 commits into from
Oct 30, 2024
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
1 change: 1 addition & 0 deletions flang/include/flang/Semantics/openmp-directive-sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ static const OmpDirectiveSet blockConstructSet{
Directive::OMPD_ordered,
Directive::OMPD_parallel,
Directive::OMPD_parallel_masked,
Directive::OMPD_parallel_master,
Directive::OMPD_parallel_workshare,
Directive::OMPD_single,
Directive::OMPD_target,
Expand Down
8 changes: 8 additions & 0 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,19 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
"MASKED TASKLOOP SIMD" >>
pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
"MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
"MASTER TASKLOOP SIMD" >>
pure(llvm::omp::Directive::OMPD_master_taskloop_simd),
"MASTER TASKLOOP" >> pure(llvm::omp::Directive::OMPD_master_taskloop),
"PARALLEL DO SIMD" >> pure(llvm::omp::Directive::OMPD_parallel_do_simd),
"PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_parallel_do),
"PARALLEL MASKED TASKLOOP SIMD" >>
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd),
"PARALLEL MASKED TASKLOOP" >>
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
"PARALLEL MASTER TASKLOOP SIMD" >>
pure(llvm::omp::Directive::OMPD_parallel_master_taskloop_simd),
"PARALLEL MASTER TASKLOOP" >>
pure(llvm::omp::Directive::OMPD_parallel_master_taskloop),
"SIMD" >> pure(llvm::omp::Directive::OMPD_simd),
"TARGET LOOP" >> pure(llvm::omp::Directive::OMPD_target_loop),
"TARGET PARALLEL DO SIMD" >>
Expand Down Expand Up @@ -695,6 +702,7 @@ TYPE_PARSER(construct<OmpBlockDirective>(first(
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master),
"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare),
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
"SINGLE" >> pure(llvm::omp::Directive::OMPD_single),
Expand Down
15 changes: 15 additions & 0 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,12 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_masked_taskloop:
Word("MASKED TASKLOOP");
break;
case llvm::omp::Directive::OMPD_master_taskloop_simd:
Word("MASTER TASKLOOP SIMD");
break;
case llvm::omp::Directive::OMPD_master_taskloop:
Word("MASTER TASKLOOP");
break;
case llvm::omp::Directive::OMPD_parallel_do:
Word("PARALLEL DO ");
break;
Expand All @@ -2276,6 +2282,12 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
Word("PARALLEL MASKED TASKLOOP");
break;
case llvm::omp::Directive::OMPD_parallel_master_taskloop_simd:
Word("PARALLEL MASTER TASKLOOP SIMD");
break;
case llvm::omp::Directive::OMPD_parallel_master_taskloop:
Word("PARALLEL MASTER TASKLOOP");
break;
case llvm::omp::Directive::OMPD_simd:
Word("SIMD ");
break;
Expand Down Expand Up @@ -2380,6 +2392,9 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_parallel_masked:
Word("PARALLEL MASKED");
break;
case llvm::omp::Directive::OMPD_parallel_master:
Word("PARALLEL MASTER");
break;
case llvm::omp::Directive::OMPD_parallel_workshare:
Word("PARALLEL WORKSHARE ");
break;
Expand Down
53 changes: 43 additions & 10 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
case llvm::omp::Directive::OMPD_masked:
case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_parallel_master:
case llvm::omp::Directive::OMPD_ordered:
case llvm::omp::Directive::OMPD_parallel:
case llvm::omp::Directive::OMPD_single:
Expand All @@ -1542,7 +1543,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
// TODO others
break;
}
if (beginDir.v == llvm::omp::Directive::OMPD_master)
if (beginDir.v == llvm::omp::Directive::OMPD_master ||
beginDir.v == llvm::omp::Directive::OMPD_parallel_master)
IssueNonConformanceWarning(beginDir.v, beginDir.source);
ClearDataSharingAttributeObjects();
ClearPrivateDataSharingAttributeObjects();
Expand All @@ -1555,7 +1557,9 @@ void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
switch (beginDir.v) {
case llvm::omp::Directive::OMPD_masked:
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_parallel_master:
case llvm::omp::Directive::OMPD_parallel:
case llvm::omp::Directive::OMPD_single:
case llvm::omp::Directive::OMPD_target:
Expand Down Expand Up @@ -1625,10 +1629,14 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
case llvm::omp::Directive::OMPD_loop:
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
case llvm::omp::Directive::OMPD_masked_taskloop:
case llvm::omp::Directive::OMPD_master_taskloop_simd:
case llvm::omp::Directive::OMPD_master_taskloop:
case llvm::omp::Directive::OMPD_parallel_do:
case llvm::omp::Directive::OMPD_parallel_do_simd:
case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
case llvm::omp::Directive::OMPD_parallel_master_taskloop_simd:
case llvm::omp::Directive::OMPD_parallel_master_taskloop:
case llvm::omp::Directive::OMPD_simd:
case llvm::omp::Directive::OMPD_target_loop:
case llvm::omp::Directive::OMPD_target_parallel_do:
Expand All @@ -1653,7 +1661,11 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
default:
break;
}
if (beginDir.v == llvm::omp::Directive::OMPD_target_loop)
if (beginDir.v == llvm::omp::OMPD_master_taskloop ||
beginDir.v == llvm::omp::OMPD_master_taskloop_simd ||
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop ||
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop_simd ||
beginDir.v == llvm::omp::Directive::OMPD_target_loop)
IssueNonConformanceWarning(beginDir.v, beginDir.source);
ClearDataSharingAttributeObjects();
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
Expand Down Expand Up @@ -2880,18 +2892,39 @@ void OmpAttributeVisitor::AddOmpRequiresToScope(Scope &scope,

void OmpAttributeVisitor::IssueNonConformanceWarning(
llvm::omp::Directive D, parser::CharBlock source) {
std::string warnStr = "";
std::string dirName = llvm::omp::getOpenMPDirectiveName(D).str();
std::string warnStr;
llvm::raw_string_ostream warnStrOS(warnStr);
warnStrOS << "OpenMP directive "
<< parser::ToUpperCaseLetters(
llvm::omp::getOpenMPDirectiveName(D).str())
<< " has been deprecated";

auto setAlternativeStr = [&warnStrOS](llvm::StringRef alt) {
warnStrOS << ", please use " << alt << " instead.";
};
switch (D) {
case llvm::omp::OMPD_master:
warnStr = "OpenMP directive '" + dirName +
"' has been deprecated, please use 'masked' instead.";
setAlternativeStr("MASKED");
break;
case llvm::omp::OMPD_master_taskloop:
setAlternativeStr("MASKED TASKLOOP");
break;
case llvm::omp::OMPD_master_taskloop_simd:
setAlternativeStr("MASKED TASKLOOP SIMD");
break;
case llvm::omp::OMPD_parallel_master:
setAlternativeStr("PARALLEL MASKED");
break;
case llvm::omp::OMPD_parallel_master_taskloop:
setAlternativeStr("PARALLEL MASKED TASKLOOP");
break;
case llvm::omp::OMPD_parallel_master_taskloop_simd:
setAlternativeStr("PARALLEL_MASKED TASKLOOP SIMD");
break;
case llvm::omp::OMPD_target_loop:
default:
warnStr = "OpenMP directive '" + dirName + "' has been deprecated.";
default:;
}
context_.Warn(
common::UsageWarning::OpenMPUsage, source, "%s"_warn_en_US, warnStr);
context_.Warn(common::UsageWarning::OpenMPUsage, source, "%s"_warn_en_US,
warnStrOS.str());
}
} // namespace Fortran::semantics
14 changes: 14 additions & 0 deletions flang/test/Lower/OpenMP/master_taskloop.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! This test checks lowering of OpenMP master taskloop Directive.

! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s

subroutine test_master_taskloop
integer :: i, j = 1
!CHECK: not yet implemented: Taskloop construct
!$omp master taskloop
do i=1,10
j = j + 1
end do
!$omp end master taskloop
end subroutine
14 changes: 14 additions & 0 deletions flang/test/Lower/OpenMP/master_taskloop_simd.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! This test checks lowering of OpenMP master taskloop simd Directive.

! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s

subroutine test_master_taskloop_simd()
integer :: i, j = 1
!CHECK: not yet implemented: Composite TASKLOOP SIMD
!$omp master taskloop simd
do i=1,10
j = j + 1
end do
!$omp end master taskloop simd
end subroutine
14 changes: 14 additions & 0 deletions flang/test/Lower/OpenMP/parallel-master-taskloop-simd.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! This test checks lowering of OpenMP parallel master taskloop simd Directive.

! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s

subroutine test_parallel_master_taskloop_simd
integer :: i, j = 1
!CHECK: not yet implemented: Composite TASKLOOP SIMD
!$omp parallel master taskloop simd
do i=1,10
j = j + 1
end do
!$omp end parallel master taskloop simd
end subroutine
14 changes: 14 additions & 0 deletions flang/test/Lower/OpenMP/parallel-master-taskloop.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! This test checks lowering of OpenMP parallel master taskloop Directive.

! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s

subroutine test_parallel_master_taskloop
integer :: i, j = 1
!CHECK: not yet implemented: Taskloop construct
!$omp parallel master taskloop
do i=1,10
j = j + 1
end do
!$omp end parallel master taskloop
end subroutine
16 changes: 16 additions & 0 deletions flang/test/Lower/OpenMP/parallel-master.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! This test checks lowering of the parallel master combined construct.

! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
! RUN: %flang_fc1 -fopenmp -emit-hlfir %s -o - | FileCheck %s

! CHECK-LABEL: func @_QPparallel_master
subroutine parallel_master(x)
integer :: x
!CHECK: omp.parallel {
!CHECK: omp.master {
!$omp parallel master
x = 1
!$omp end parallel master
!CHECK: }
!CHECK: }
end subroutine parallel_master
73 changes: 73 additions & 0 deletions flang/test/Parser/OpenMP/master-unparse.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case %s
! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s

! Check for parsing of master directive


subroutine test_master()
integer :: c = 1
!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = master
!CHECK: !$omp master
!$omp master
c = c + 1
!$omp end master
end subroutine

subroutine test_master_taskloop_simd()
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = master taskloop simd
!CHECK: !$omp master taskloop simd
!$omp master taskloop simd
do i=1,10
j = j + 1
end do
!$omp end master taskloop simd
end subroutine

subroutine test_master_taskloop
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = master taskloop
!CHECK: !$omp master taskloop
!$omp master taskloop
do i=1,10
j = j + 1
end do
!$omp end master taskloop
end subroutine

subroutine test_parallel_master
integer :: c = 2
!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel master
!CHECK: !$omp parallel master
!$omp parallel master
c = c + 2
!$omp end parallel master
end subroutine

subroutine test_parallel_master_taskloop_simd
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel master taskloop simd
!CHECK: !$omp parallel master taskloop simd
!$omp parallel master taskloop simd
do i=1,10
j = j + 1
end do
!$omp end parallel master taskloop simd
end subroutine

subroutine test_parallel_master_taskloop
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel master taskloop
!CHECK: !$omp parallel master taskloop
!$omp parallel master taskloop
do i=1,10
j = j + 1
end do
!$omp end parallel master taskloop
end subroutine
4 changes: 2 additions & 2 deletions flang/test/Semantics/OpenMP/clause-validity01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,14 @@
! 2.13.1 master

!$omp parallel
!WARNING: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
!$omp master
a=3.14
!$omp end master
!$omp end parallel

!$omp parallel
!WARNING: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
!ERROR: NUM_THREADS clause is not allowed on the MASTER directive
!$omp master num_threads(4)
a=3.14
Expand Down
Loading
Loading