Skip to content

Adding parsing support for omp loop, target loop directives #93517

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
Jun 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
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 @@ -242,6 +242,7 @@ static const OmpDirectiveSet loopConstructSet{
Directive::OMPD_parallel_master_taskloop,
Directive::OMPD_parallel_master_taskloop_simd,
Directive::OMPD_simd,
Directive::OMPD_target_loop,
Directive::OMPD_target_parallel_do,
Directive::OMPD_target_parallel_do_simd,
Directive::OMPD_target_parallel_loop,
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ 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),
"LOOP" >> pure(llvm::omp::Directive::OMPD_loop),
"MASKED TASKLOOP SIMD" >>
pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
"MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
Expand All @@ -388,9 +389,12 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
"PARALLEL MASKED TASKLOOP" >>
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
"SIMD" >> pure(llvm::omp::Directive::OMPD_simd),
"TARGET LOOP" >> pure(llvm::omp::Directive::OMPD_target_loop),
"TARGET PARALLEL DO SIMD" >>
pure(llvm::omp::Directive::OMPD_target_parallel_do_simd),
"TARGET PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_target_parallel_do),
"TARGET PARALLEL LOOP" >>
pure(llvm::omp::Directive::OMPD_target_parallel_loop),
"TARGET SIMD" >> pure(llvm::omp::Directive::OMPD_target_simd),
"TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD" >>
pure(llvm::omp::Directive::
Expand All @@ -401,6 +405,7 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
pure(llvm::omp::Directive::OMPD_target_teams_distribute_simd),
"TARGET TEAMS DISTRIBUTE" >>
pure(llvm::omp::Directive::OMPD_target_teams_distribute),
"TARGET TEAMS LOOP" >> pure(llvm::omp::Directive::OMPD_target_teams_loop),
"TASKLOOP SIMD" >> pure(llvm::omp::Directive::OMPD_taskloop_simd),
"TASKLOOP" >> pure(llvm::omp::Directive::OMPD_taskloop),
"TEAMS DISTRIBUTE PARALLEL DO SIMD" >>
Expand Down
12 changes: 12 additions & 0 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,9 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_do_simd:
Word("DO SIMD ");
break;
case llvm::omp::Directive::OMPD_loop:
Word("LOOP ");
break;
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
Word("MASKED TASKLOOP SIMD");
break;
Expand All @@ -2228,12 +2231,18 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_simd:
Word("SIMD ");
break;
case llvm::omp::Directive::OMPD_target_loop:
Word("TARGET LOOP ");
break;
case llvm::omp::Directive::OMPD_target_parallel_do:
Word("TARGET PARALLEL DO ");
break;
case llvm::omp::Directive::OMPD_target_parallel_do_simd:
Word("TARGET PARALLEL DO SIMD ");
break;
case llvm::omp::Directive::OMPD_target_parallel_loop:
Word("TARGET PARALLEL LOOP ");
break;
case llvm::omp::Directive::OMPD_target_teams_distribute:
Word("TARGET TEAMS DISTRIBUTE ");
break;
Expand All @@ -2246,6 +2255,9 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_target_teams_distribute_simd:
Word("TARGET TEAMS DISTRIBUTE SIMD ");
break;
case llvm::omp::Directive::OMPD_target_teams_loop:
Word("TARGET TEAMS LOOP ");
break;
case llvm::omp::Directive::OMPD_target_simd:
Word("TARGET SIMD ");
break;
Expand Down
10 changes: 10 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1602,19 +1602,23 @@ 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_loop:
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_loop:
case llvm::omp::Directive::OMPD_target_parallel_do:
case llvm::omp::Directive::OMPD_target_parallel_do_simd:
case llvm::omp::Directive::OMPD_target_parallel_loop:
case llvm::omp::Directive::OMPD_target_teams_distribute:
case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do:
case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do_simd:
case llvm::omp::Directive::OMPD_target_teams_distribute_simd:
case llvm::omp::Directive::OMPD_target_teams_loop:
case llvm::omp::Directive::OMPD_target_simd:
case llvm::omp::Directive::OMPD_taskloop:
case llvm::omp::Directive::OMPD_taskloop_simd:
Expand All @@ -1629,6 +1633,12 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
default:
break;
}
if (beginDir.v == llvm::omp::Directive::OMPD_target_loop)
if (context_.ShouldWarn(common::UsageWarning::OpenMPUsage)) {
context_.Say(beginDir.source,
"Usage of directive %s is non-confirming to OpenMP standard"_warn_en_US,
llvm::omp::getOpenMPDirectiveName(beginDir.v).str());
}
ClearDataSharingAttributeObjects();
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));

Expand Down
15 changes: 15 additions & 0 deletions flang/test/Lower/OpenMP/Todo/loop-directive.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
! This test checks lowering of OpenMP loop 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 loop
subroutine test_loop()
integer :: i, j = 1
!$omp loop
do i=1,10
j = j + 1
end do
!$omp end loop
end subroutine

53 changes: 53 additions & 0 deletions flang/test/Parser/OpenMP/target-loop-unparse.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

! 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 loop directive

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

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

subroutine test_target_teams_loop
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target teams loop
!CHECK: !$omp target teams loop
!$omp target teams loop
do i=1,10
j = j + 1
end do
!$omp end target teams loop
end subroutine

subroutine test_target_parallel_loop
integer :: i, j = 1
!PARSE-TREE: OmpBeginLoopDirective
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target parallel loop
!CHECK: !$omp target parallel loop
!$omp target parallel loop
do i=1,10
j = j + 1
end do
!$omp end target parallel loop
end subroutine
30 changes: 30 additions & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMP.td
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,36 @@ def OMP_ForSimd : Directive<"for simd"> {
let leafConstructs = [OMP_For, OMP_Simd];
let category = CA_Executable;
}
def OMP_target_loop : Directive<"target loop"> {
let allowedClauses = [
VersionedClause<OMPC_Allocate>,
VersionedClause<OMPC_Depend>,
VersionedClause<OMPC_FirstPrivate>,
VersionedClause<OMPC_IsDevicePtr>,
VersionedClause<OMPC_HasDeviceAddr, 51>,
VersionedClause<OMPC_LastPrivate>,
VersionedClause<OMPC_Map>,
VersionedClause<OMPC_Private>,
VersionedClause<OMPC_Reduction>,
VersionedClause<OMPC_UsesAllocators, 50>,
VersionedClause<OMPC_OMPX_Attribute>,
VersionedClause<OMPC_InReduction, 50>,

];
let allowedOnceClauses = [
VersionedClause<OMPC_Bind, 50>,
VersionedClause<OMPC_Collapse>,
VersionedClause<OMPC_Order>,
VersionedClause<OMPC_ThreadLimit>,
VersionedClause<OMPC_OMPX_DynCGroupMem>,
VersionedClause<OMPC_If>,
VersionedClause<OMPC_Device>,
VersionedClause<OMPC_DefaultMap>,
VersionedClause<OMPC_NoWait>,
];
let leafConstructs = [OMP_Target, OMP_loop];
let category = CA_Executable;
}
def OMP_MaskedTaskloop : Directive<"masked taskloop"> {
let allowedClauses = [
VersionedClause<OMPC_Allocate>,
Expand Down
Loading