[flang-commits] [flang] 826bde5 - Adding parsing support for omp loop, target loop directives (#93517)
via flang-commits
flang-commits at lists.llvm.org
Thu Jun 20 21:10:38 PDT 2024
Author: Anchu Rajendran S
Date: 2024-06-21T09:40:34+05:30
New Revision: 826bde5d8ae9f89b71d14453c631f1d76932c2d8
URL: https://github.com/llvm/llvm-project/commit/826bde5d8ae9f89b71d14453c631f1d76932c2d8
DIFF: https://github.com/llvm/llvm-project/commit/826bde5d8ae9f89b71d14453c631f1d76932c2d8.diff
LOG: Adding parsing support for omp loop, target loop directives (#93517)
Change adds parsing support for omp loop, omp target loop, omp target
parallel loop and omp target teams loop.
Added:
flang/test/Lower/OpenMP/Todo/loop-directive.f90
flang/test/Parser/OpenMP/target-loop-unparse.f90
Modified:
flang/include/flang/Semantics/openmp-directive-sets.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/resolve-directives.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td
Removed:
################################################################################
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..0ea48ce29ca2f 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,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::
@@ -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" >>
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 036f306c02cbf..2511a5dda9d09 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -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;
@@ -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;
@@ -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;
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index dbc531372c3f4..0bf63a00bdf91 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:
@@ -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));
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 12a944e34c414..dcb4608b687d7 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -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>,
More information about the flang-commits
mailing list