Skip to content

Commit a01657c

Browse files
committed
[flang][OpenMP] Add parsing support for Task detach
1 parent d37bc32 commit a01657c

File tree

8 files changed

+48
-2
lines changed

8 files changed

+48
-2
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,6 +3516,11 @@ struct OmpIfClause {
35163516
std::tuple<std::optional<DirectiveNameModifier>, ScalarLogicalExpr> t;
35173517
};
35183518

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

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ Destroy make(const parser::OmpClause::Destroy &inp,
572572

573573
Detach make(const parser::OmpClause::Detach &inp,
574574
semantics::SemanticsContext &semaCtx) {
575-
// inp -> empty
576-
llvm_unreachable("Empty: detach");
575+
// inp.v -> parser::OmpDetachClause
576+
return Detach{makeObject(inp.v.v, semaCtx)};
577577
}
578578

579579
Device make(const parser::OmpClause::Device &inp,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
// OpenMPv5.2 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(":");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! REQUIRES: omp_lib
2+
! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
3+
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
4+
5+
!===============================================================================
6+
! `detach` clause
7+
!===============================================================================
8+
9+
! CHECK: not yet implemented: OpenMP Block construct clause
10+
subroutine omp_task_detach()
11+
use omp_lib
12+
integer (kind=omp_event_handle_kind) :: event
13+
!$omp task detach(event)
14+
call foo()
15+
!$omp end task
16+
end subroutine omp_task_detach

flang/test/Parser/OpenMP/task.f90

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