Skip to content

Commit cea1f26

Browse files
committed
[flang][OpenMP] Add parsing support for detach clause
1 parent 3733b0c commit cea1f26

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ class ParseTreeDumper {
507507
NODE_ENUM(OmpDefaultmapClause, ImplicitBehavior)
508508
NODE_ENUM(OmpDefaultmapClause, VariableCategory)
509509
NODE(parser, OmpDependClause)
510+
NODE(parser, OmpDetachClause)
510511
NODE(OmpDependClause, InOut)
511512
NODE(OmpDependClause, Sink)
512513
NODE(OmpDependClause, Source)

flang/include/flang/Parser/parse-tree.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,6 +3515,12 @@ struct OmpIfClause {
35153515
std::tuple<std::optional<DirectiveNameModifier>, ScalarLogicalExpr> t;
35163516
};
35173517

3518+
// OpenMPv5.2 12.5.2 detach-clause -> DETACH (event-handle)
3519+
struct OmpDetachClause {
3520+
WRAPPER_CLASS_BOILERPLATE(OmpDetachClause, OmpObject);
3521+
CharBlock source;
3522+
};
3523+
35183524
// 2.8.1 aligned-clause -> ALIGNED (variable-name-list[ : scalar-constant])
35193525
struct OmpAlignedClause {
35203526
TUPLE_CLASS_BOILERPLATE(OmpAlignedClause);

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ TYPE_PARSER(construct<OmpIfClause>(
215215
":"),
216216
scalarLogicalExpr))
217217

218-
// 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list)
218+
// OpenMPv5.2 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list)
219219
TYPE_PARSER(construct<OmpReductionOperator>(Parser<DefinedOperator>{}) ||
220220
construct<OmpReductionOperator>(Parser<ProcedureDesignator>{}))
221221

@@ -298,6 +298,9 @@ TYPE_CONTEXT_PARSER("Omp LINEAR clause"_en_US,
298298
construct<OmpLinearClause>(construct<OmpLinearClause::WithoutModifier>(
299299
nonemptyList(name), maybe(":" >> scalarIntConstantExpr)))))
300300

301+
// 12.5.2 detach-clause -> DETACH (event-handle)
302+
TYPE_PARSER(construct<OmpDetachClause>(Parser<OmpObject>{}))
303+
301304
// 2.8.1 ALIGNED (list: alignment)
302305
TYPE_PARSER(construct<OmpAlignedClause>(
303306
Parser<OmpObjectList>{}, maybe(":" >> scalarIntConstantExpr)))
@@ -414,6 +417,8 @@ TYPE_PARSER(
414417
parenthesized(Parser<OmpReductionClause>{}))) ||
415418
"IN_REDUCTION" >> construct<OmpClause>(construct<OmpClause::InReduction>(
416419
parenthesized(Parser<OmpInReductionClause>{}))) ||
420+
"DETACH" >> construct<OmpClause>(construct<OmpClause::Detach>(
421+
parenthesized(Parser<OmpDetachClause>{}))) ||
417422
"TASK_REDUCTION" >>
418423
construct<OmpClause>(construct<OmpClause::TaskReduction>(
419424
parenthesized(Parser<OmpReductionClause>{}))) ||

flang/lib/Parser/unparse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,7 @@ class UnparseVisitor {
21312131
Put(":");
21322132
Walk(std::get<OmpObjectList>(x.t));
21332133
}
2134+
void Unparse(const OmpDetachClause &x) { Walk(x.v); }
21342135
void Unparse(const OmpInReductionClause &x) {
21352136
Walk(std::get<OmpReductionOperator>(x.t));
21362137
Put(":");

flang/test/Parser/OpenMP/task.f90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case %s
2+
! RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case --check-prefix="CHECK-UNPARSE" %s
3+
4+
!CHECK: OmpBlockDirective -> llvm::omp::Directive = task
5+
!CHECK: OmpClauseList -> OmpClause -> Detach -> OmpDetachClause -> OmpObject -> Designator -> DataRef -> Name = 'event'
6+
7+
!CHECK-UNPARSE: INTEGER(KIND=8_4) event
8+
!CHECK-UNPARSE: !$OMP TASK DETACH(event)
9+
!CHECK-UNPARSE: !$OMP END TASK
10+
subroutine task_detach
11+
use omp_lib
12+
implicit none
13+
integer(kind=omp_event_handle_kind) :: event
14+
!$omp task detach(event)
15+
!$omp end task
16+
end subroutine

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def OMPC_Destroy : Clause<"destroy"> {
132132
}
133133
def OMPC_Detach : Clause<"detach"> {
134134
let clangClass = "OMPDetachClause";
135+
let flangClass = "OmpDetachClause";
135136
}
136137
def OMPC_Device : Clause<"device"> {
137138
let clangClass = "OMPDeviceClause";

0 commit comments

Comments
 (0)