[flang-commits] [flang] [llvm] Adding parsing support for omp loop, target loop directives (PR #93517)
via flang-commits
flang-commits at lists.llvm.org
Tue May 28 02:21:33 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
Author: Anchu Rajendran S (anchuraj)
<details>
<summary>Changes</summary>
Change adds parsing support for omp loop, omp target loop, omp target parallel loop and omp target teams loop.
---
Full diff: https://github.com/llvm/llvm-project/pull/93517.diff
7 Files Affected:
- (modified) flang/include/flang/Semantics/openmp-directive-sets.h (+1)
- (modified) flang/lib/Parser/openmp-parsers.cpp (+7)
- (modified) flang/lib/Parser/unparse.cpp (+12)
- (modified) flang/lib/Semantics/resolve-directives.cpp (+4)
- (added) flang/test/Lower/OpenMP/Todo/loop-directive.f90 (+15)
- (added) flang/test/Parser/OpenMP/target-loop-unparse.f90 (+53)
- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+29)
``````````diff
diff --git a/flang/include/flang/Semantics/openmp-directive-sets.h b/flang/include/flang/Semantics/openmp-directive-sets.h
index da66e0eda3216..8eb736bb098fe 100644
--- a/flang/include/flang/Semantics/openmp-directive-sets.h
+++ b/flang/include/flang/Semantics/openmp-directive-sets.h
@@ -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,
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index e67dbcca30e7d..cc6b7b2c60913 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -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),
@@ -388,9 +389,13 @@ 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::
@@ -401,6 +406,8 @@ 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" >>
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index bdd968b19a43f..8131d336b5eb9 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2194,6 +2194,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;
@@ -2215,12 +2218,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;
@@ -2233,6 +2242,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;
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index dbc531372c3f4..789e0f089fe6a 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1602,6 +1602,7 @@ 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:
@@ -1609,12 +1610,15 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
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:
diff --git a/flang/test/Lower/OpenMP/Todo/loop-directive.f90 b/flang/test/Lower/OpenMP/Todo/loop-directive.f90
new file mode 100644
index 0000000000000..f1aea70458aa6
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/loop-directive.f90
@@ -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
+
diff --git a/flang/test/Parser/OpenMP/target-loop-unparse.f90 b/flang/test/Parser/OpenMP/target-loop-unparse.f90
new file mode 100644
index 0000000000000..3ee2fcef075a3
--- /dev/null
+++ b/flang/test/Parser/OpenMP/target-loop-unparse.f90
@@ -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
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index e91169e8da1aa..e4c7df5f11208 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -2232,6 +2232,35 @@ def OMP_teams_loop : Directive<"teams loop"> {
];
let leafConstructs = [OMP_Teams, OMP_loop];
}
+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];
+}
def OMP_target_teams_loop : Directive<"target teams loop"> {
let allowedClauses = [
VersionedClause<OMPC_If>,
``````````
</details>
https://github.com/llvm/llvm-project/pull/93517
More information about the flang-commits
mailing list