Skip to content

Adding parsing and semantic check support for omp masked #91432

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 6 commits into from
May 21, 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
2 changes: 2 additions & 0 deletions flang/include/flang/Semantics/openmp-directive-sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,11 @@ static const OmpDirectiveSet compositeConstructSet{
};

static const OmpDirectiveSet blockConstructSet{
Directive::OMPD_masked,
Directive::OMPD_master,
Directive::OMPD_ordered,
Directive::OMPD_parallel,
Directive::OMPD_parallel_masked,
Directive::OMPD_parallel_workshare,
Directive::OMPD_single,
Directive::OMPD_target,
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1971,8 +1971,7 @@ static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
break;
case llvm::omp::Directive::OMPD_loop:
case llvm::omp::Directive::OMPD_masked:
TODO(loc, "Unhandled loop directive (" +
llvm::omp::getOpenMPDirectiveName(dir) + ")");
TODO(loc, "Unhandled directive " + llvm::omp::getOpenMPDirectiveName(dir));
break;
case llvm::omp::Directive::OMPD_master:
genMasterOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
Expand Down
11 changes: 11 additions & 0 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ TYPE_PARSER(
construct<OmpClause>(construct<OmpClause::DynamicAllocators>()) ||
"ENTER" >> construct<OmpClause>(construct<OmpClause::Enter>(
parenthesized(Parser<OmpObjectList>{}))) ||
"FILTER" >> construct<OmpClause>(construct<OmpClause::Filter>(
parenthesized(scalarIntExpr))) ||
"FINAL" >> construct<OmpClause>(construct<OmpClause::Final>(
parenthesized(scalarLogicalExpr))) ||
"FULL" >> construct<OmpClause>(construct<OmpClause::Full>()) ||
Expand Down Expand Up @@ -376,8 +378,15 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
"DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_distribute),
"DO SIMD" >> pure(llvm::omp::Directive::OMPD_do_simd),
"DO" >> pure(llvm::omp::Directive::OMPD_do),
"MASKED TASKLOOP SIMD" >>
pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
"MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_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),
"SIMD" >> pure(llvm::omp::Directive::OMPD_simd),
"TARGET PARALLEL DO SIMD" >>
pure(llvm::omp::Directive::OMPD_target_parallel_do_simd),
Expand Down Expand Up @@ -487,8 +496,10 @@ TYPE_PARSER(

// Directives enclosing structured-block
TYPE_PARSER(construct<OmpBlockDirective>(first(
"MASKED" >> pure(llvm::omp::Directive::OMPD_masked),
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
"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
18 changes: 18 additions & 0 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2194,12 +2194,24 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_do_simd:
Word("DO SIMD ");
break;
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
Word("MASKED TASKLOOP SIMD");
break;
case llvm::omp::Directive::OMPD_masked_taskloop:
Word("MASKED TASKLOOP");
break;
case llvm::omp::Directive::OMPD_parallel_do:
Word("PARALLEL DO ");
break;
case llvm::omp::Directive::OMPD_parallel_do_simd:
Word("PARALLEL DO SIMD ");
break;
case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
Word("PARALLEL MASKED TASKLOOP SIMD");
break;
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
Word("PARALLEL MASKED TASKLOOP");
break;
case llvm::omp::Directive::OMPD_simd:
Word("SIMD ");
break;
Expand Down Expand Up @@ -2283,12 +2295,18 @@ class UnparseVisitor {
}
void Unparse(const OmpBlockDirective &x) {
switch (x.v) {
case llvm::omp::Directive::OMPD_masked:
Word("MASKED");
break;
case llvm::omp::Directive::OMPD_master:
Word("MASTER");
break;
case llvm::omp::Directive::OMPD_ordered:
Word("ORDERED ");
break;
case llvm::omp::Directive::OMPD_parallel_masked:
Word("PARALLEL MASKED");
break;
case llvm::omp::Directive::OMPD_parallel_workshare:
Word("PARALLEL WORKSHARE ");
break;
Expand Down
8 changes: 8 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
switch (beginDir.v) {
case llvm::omp::Directive::OMPD_masked:
case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_ordered:
case llvm::omp::Directive::OMPD_parallel:
Expand Down Expand Up @@ -1532,6 +1534,8 @@ void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
switch (beginDir.v) {
case llvm::omp::Directive::OMPD_masked:
case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_parallel:
case llvm::omp::Directive::OMPD_single:
case llvm::omp::Directive::OMPD_target:
Expand Down Expand Up @@ -1598,8 +1602,12 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
case llvm::omp::Directive::OMPD_distribute_simd:
case llvm::omp::Directive::OMPD_do:
case llvm::omp::Directive::OMPD_do_simd:
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
case llvm::omp::Directive::OMPD_masked_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_simd:
case llvm::omp::Directive::OMPD_target_parallel_do:
case llvm::omp::Directive::OMPD_target_parallel_do_simd:
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Lower/OpenMP/Todo/masked-directive.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
! This test checks lowering of OpenMP masked 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

! CHECK: not yet implemented: Unhandled directive masked
subroutine test_masked()
integer :: c = 1
!$omp masked
c = c + 1
!$omp end masked
end subroutine

92 changes: 92 additions & 0 deletions flang/test/Parser/OpenMP/masked-unparse.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
! 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 masked directive with filter clause.


subroutine test_masked()
integer :: c = 1
!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked
!CHECK: !$omp masked
!$omp masked
c = c + 1
!$omp end masked
!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked
!PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '1_4'
!PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '1'
!CHECK: !$omp masked filter(1_4)
!$omp masked filter(1)
c = c + 2
!$omp end masked
end subroutine

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

subroutine test_masked_taskloop
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = masked taskloop
!PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
!PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2'
!CHECK: !$omp masked taskloop filter(2_4)
!$omp masked taskloop filter(2)
do i=1,10
j = j + 1
end do
!$omp end masked taskloop
end subroutine

subroutine test_parallel_masked
integer, parameter :: i = 1, j = 1
integer :: c = 2
!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel masked
!PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
!PARSE-TREE-NEXT: Add
!PARSE-TREE-NEXT: Expr = '1_4'
!PARSE-TREE-NEXT: Designator -> DataRef -> Name = 'i'
!PARSE-TREE-NEXT: Expr = '1_4'
!PARSE-TREE-NEXT: Designator -> DataRef -> Name = 'j'
!CHECK: !$omp parallel masked filter(2_4)
!$omp parallel masked filter(i+j)
c = c + 2
!$omp end parallel masked
end subroutine

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

subroutine test_parallel_masked_taskloop
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel masked taskloop
!PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
!PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2'
!CHECK: !$omp parallel masked taskloop filter(2_4)
!$omp parallel masked taskloop filter(2)
do i=1,10
j = j + 1
end do
!$omp end parallel masked taskloop
end subroutine
13 changes: 13 additions & 0 deletions flang/test/Semantics/OpenMP/masked.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp

subroutine test_masked()
integer :: c = 1
!ERROR: At most one FILTER clause can appear on the MASKED directive
!$omp masked filter(1) filter(2)
c = c + 1
!$omp end masked
!ERROR: NOWAIT clause is not allowed on the MASKED directive
!$omp masked nowait
c = c + 2
!$omp end masked
end subroutine
Loading