[flang] [llvm] [flang][OpenMP] Add parsing support for Task detach (PR #112312)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 22:49:04 PDT 2024
https://github.com/NimishMishra created https://github.com/llvm/llvm-project/pull/112312
Add parsing support for task detach, along with parse/unparse tests.
>From d47b54bb50f3b630fbe7a43ba519c84b738b71c4 Mon Sep 17 00:00:00 2001
From: Nimish Mishra <neelam.nimish at gmail.com>
Date: Tue, 8 Oct 2024 10:20:11 +0530
Subject: [PATCH 1/2] Add parser support for task detach
---
flang/include/flang/Parser/dump-parse-tree.h | 1 +
flang/include/flang/Parser/parse-tree.h | 6 ++++++
flang/lib/Parser/openmp-parsers.cpp | 6 ++++++
flang/lib/Parser/unparse.cpp | 3 +++
flang/test/Parser/OpenMP/task.f90 | 16 ++++++++++++++++
llvm/include/llvm/Frontend/OpenMP/OMP.td | 1 +
6 files changed, 33 insertions(+)
create mode 100644 flang/test/Parser/OpenMP/task.f90
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 5d243b4e5d3e9a..3f7a26d2103bae 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -475,6 +475,7 @@ class ParseTreeDumper {
NODE(parser, ObjectDecl)
NODE(parser, OldParameterStmt)
NODE(parser, OmpAlignedClause)
+ NODE(parser, OmpDetachClause);
NODE(parser, OmpAtomic)
NODE(parser, OmpAtomicCapture)
NODE(OmpAtomicCapture, Stmt1)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 21b4a344dbc438..abbf5bc2eabc4f 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3515,6 +3515,12 @@ struct OmpIfClause {
std::tuple<std::optional<DirectiveNameModifier>, ScalarLogicalExpr> t;
};
+// 12.5.2 detach-clause -> DETACH (event-handle)
+struct OmpDetachClause {
+ WRAPPER_CLASS_BOILERPLATE(OmpDetachClause, OmpObject);
+ CharBlock source;
+};
+
// 2.8.1 aligned-clause -> ALIGNED (variable-name-list[ : scalar-constant])
struct OmpAlignedClause {
TUPLE_CLASS_BOILERPLATE(OmpAlignedClause);
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 8634c522cf343a..81635422264d2b 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -298,6 +298,10 @@ TYPE_CONTEXT_PARSER("Omp LINEAR clause"_en_US,
construct<OmpLinearClause>(construct<OmpLinearClause::WithoutModifier>(
nonemptyList(name), maybe(":" >> scalarIntConstantExpr)))))
+// 12.5.2 detach-clause -> DETACH (event-handle)
+TYPE_PARSER(construct<OmpDetachClause>(
+ Parser<OmpObject>{}))
+
// 2.8.1 ALIGNED (list: alignment)
TYPE_PARSER(construct<OmpAlignedClause>(
Parser<OmpObjectList>{}, maybe(":" >> scalarIntConstantExpr)))
@@ -414,6 +418,8 @@ TYPE_PARSER(
parenthesized(Parser<OmpReductionClause>{}))) ||
"IN_REDUCTION" >> construct<OmpClause>(construct<OmpClause::InReduction>(
parenthesized(Parser<OmpInReductionClause>{}))) ||
+ "DETACH" >> construct<OmpClause>(construct<OmpClause::Detach>(
+ parenthesized(Parser<OmpDetachClause>{}))) ||
"TASK_REDUCTION" >>
construct<OmpClause>(construct<OmpClause::TaskReduction>(
parenthesized(Parser<OmpReductionClause>{}))) ||
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index d1011fe58a0264..bb8ec168ced2d5 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2131,6 +2131,9 @@ class UnparseVisitor {
Put(":");
Walk(std::get<OmpObjectList>(x.t));
}
+ void Unparse(const OmpDetachClause &x){
+ Walk(x.v);
+ }
void Unparse(const OmpInReductionClause &x) {
Walk(std::get<OmpReductionOperator>(x.t));
Put(":");
diff --git a/flang/test/Parser/OpenMP/task.f90 b/flang/test/Parser/OpenMP/task.f90
new file mode 100644
index 00000000000000..dbeb6e51b345b1
--- /dev/null
+++ b/flang/test/Parser/OpenMP/task.f90
@@ -0,0 +1,16 @@
+! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case %s
+! RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case --check-prefix="CHECK-UNPARSE" %s
+
+!CHECK: OmpBlockDirective -> llvm::omp::Directive = task
+!CHECK: OmpClauseList -> OmpClause -> Detach -> OmpDetachClause -> OmpObject -> Designator -> DataRef -> Name = 'event'
+
+!CHECK-UNPARSE: INTEGER(KIND=8_4) event
+!CHECK-UNPARSE: !$OMP TASK DETACH(event)
+!CHECK-UNPARSE: !$OMP END TASK
+subroutine task_detach
+ use omp_lib
+ implicit none
+ integer(kind=omp_event_handle_kind) :: event
+ !$omp task detach(event)
+ !$omp end task
+end subroutine
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index f2f09812a86905..6ed224f0857a9b 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -132,6 +132,7 @@ def OMPC_Destroy : Clause<"destroy"> {
}
def OMPC_Detach : Clause<"detach"> {
let clangClass = "OMPDetachClause";
+ let flangClass = "OmpDetachClause";
}
def OMPC_Device : Clause<"device"> {
let clangClass = "OMPDeviceClause";
>From 2a51b4d0291f4e722f6730449796aec0e5f76fa3 Mon Sep 17 00:00:00 2001
From: Nimish Mishra <neelam.nimish at gmail.com>
Date: Tue, 15 Oct 2024 11:15:05 +0530
Subject: [PATCH 2/2] Minor changes
---
flang/include/flang/Parser/dump-parse-tree.h | 2 +-
flang/include/flang/Parser/parse-tree.h | 2 +-
flang/lib/Parser/openmp-parsers.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 3f7a26d2103bae..f21eae3b92d5bd 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -475,7 +475,6 @@ class ParseTreeDumper {
NODE(parser, ObjectDecl)
NODE(parser, OldParameterStmt)
NODE(parser, OmpAlignedClause)
- NODE(parser, OmpDetachClause);
NODE(parser, OmpAtomic)
NODE(parser, OmpAtomicCapture)
NODE(OmpAtomicCapture, Stmt1)
@@ -508,6 +507,7 @@ class ParseTreeDumper {
NODE_ENUM(OmpDefaultmapClause, ImplicitBehavior)
NODE_ENUM(OmpDefaultmapClause, VariableCategory)
NODE(parser, OmpDependClause)
+ NODE(parser, OmpDetachClause)
NODE(OmpDependClause, InOut)
NODE(OmpDependClause, Sink)
NODE(OmpDependClause, Source)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index abbf5bc2eabc4f..484aaf50e223f0 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3515,7 +3515,7 @@ struct OmpIfClause {
std::tuple<std::optional<DirectiveNameModifier>, ScalarLogicalExpr> t;
};
-// 12.5.2 detach-clause -> DETACH (event-handle)
+// OpenMPv5.2 12.5.2 detach-clause -> DETACH (event-handle)
struct OmpDetachClause {
WRAPPER_CLASS_BOILERPLATE(OmpDetachClause, OmpObject);
CharBlock source;
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 81635422264d2b..2a67f87128588f 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -215,7 +215,7 @@ TYPE_PARSER(construct<OmpIfClause>(
":"),
scalarLogicalExpr))
-// 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list)
+// OpenMPv5.2 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list)
TYPE_PARSER(construct<OmpReductionOperator>(Parser<DefinedOperator>{}) ||
construct<OmpReductionOperator>(Parser<ProcedureDesignator>{}))
More information about the llvm-commits
mailing list