[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:54:14 PDT 2024
https://github.com/NimishMishra updated https://github.com/llvm/llvm-project/pull/112312
>From cea1f26fe2f11d2b885ec39ca187746e7a637c45 Mon Sep 17 00:00:00 2001
From: Nimish Mishra <neelam.nimish at gmail.com>
Date: Tue, 15 Oct 2024 11:23:58 +0530
Subject: [PATCH] [flang][OpenMP] Add parsing support for detach clause
---
flang/include/flang/Parser/dump-parse-tree.h | 1 +
flang/include/flang/Parser/parse-tree.h | 6 ++++++
flang/lib/Parser/openmp-parsers.cpp | 7 ++++++-
flang/lib/Parser/unparse.cpp | 1 +
flang/test/Parser/OpenMP/task.f90 | 16 ++++++++++++++++
llvm/include/llvm/Frontend/OpenMP/OMP.td | 1 +
6 files changed, 31 insertions(+), 1 deletion(-)
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..f21eae3b92d5bd 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -507,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 21b4a344dbc438..484aaf50e223f0 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;
};
+// OpenMPv5.2 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..041459857d0364 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>{}))
@@ -298,6 +298,9 @@ 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 +417,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..3ac87430231ed3 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2131,6 +2131,7 @@ 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";
More information about the llvm-commits
mailing list