Skip to content

Commit 0653698

Browse files
authored
[flang][OpenMP] Add parsing support for Task detach (#112312)
Add parsing support for task detach, along with parse/unparse tests.
1 parent a517127 commit 0653698

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
@@ -510,6 +510,7 @@ class ParseTreeDumper {
510510
NODE_ENUM(OmpDefaultmapClause, ImplicitBehavior)
511511
NODE_ENUM(OmpDefaultmapClause, VariableCategory)
512512
NODE(parser, OmpDependClause)
513+
NODE(parser, OmpDetachClause)
513514
NODE(OmpDependClause, InOut)
514515
NODE(OmpDependClause, Sink)
515516
NODE(OmpDependClause, Source)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3597,6 +3597,11 @@ struct OmpIfClause {
35973597
std::tuple<std::optional<DirectiveNameModifier>, ScalarLogicalExpr> t;
35983598
};
35993599

3600+
// OpenMPv5.2 12.5.2 detach-clause -> DETACH (event-handle)
3601+
struct OmpDetachClause {
3602+
WRAPPER_CLASS_BOILERPLATE(OmpDetachClause, OmpObject);
3603+
};
3604+
36003605
// OMP 5.0 2.19.5.6 in_reduction-clause -> IN_REDUCTION (reduction-identifier:
36013606
// variable-name-list)
36023607
struct OmpInReductionClause {

flang/lib/Lower/OpenMP/Clauses.cpp

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

636636
Detach make(const parser::OmpClause::Detach &inp,
637637
semantics::SemanticsContext &semaCtx) {
638-
// inp -> empty
639-
llvm_unreachable("Empty: detach");
638+
// inp.v -> parser::OmpDetachClause
639+
return Detach{makeObject(inp.v.v, semaCtx)};
640640
}
641641

642642
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
@@ -398,6 +398,9 @@ TYPE_CONTEXT_PARSER("Omp LINEAR clause"_en_US,
398398
construct<OmpLinearClause>(construct<OmpLinearClause::WithoutModifier>(
399399
nonemptyList(name), maybe(":" >> scalarIntConstantExpr)))))
400400

401+
// OpenMPv5.2 12.5.2 detach-clause -> DETACH (event-handle)
402+
TYPE_PARSER(construct<OmpDetachClause>(Parser<OmpObject>{}))
403+
401404
// 2.8.1 ALIGNED (list: alignment)
402405
TYPE_PARSER(construct<OmpAlignedClause>(
403406
Parser<OmpObjectList>{}, maybe(":" >> scalarIntConstantExpr)))
@@ -529,6 +532,8 @@ TYPE_PARSER(
529532
parenthesized(Parser<OmpReductionClause>{}))) ||
530533
"IN_REDUCTION" >> construct<OmpClause>(construct<OmpClause::InReduction>(
531534
parenthesized(Parser<OmpInReductionClause>{}))) ||
535+
"DETACH" >> construct<OmpClause>(construct<OmpClause::Detach>(
536+
parenthesized(Parser<OmpDetachClause>{}))) ||
532537
"TASK_REDUCTION" >>
533538
construct<OmpClause>(construct<OmpClause::TaskReduction>(
534539
parenthesized(Parser<OmpReductionClause>{}))) ||

flang/lib/Parser/unparse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,7 @@ class UnparseVisitor {
21572157
Put(":");
21582158
Walk(std::get<OmpObjectList>(x.t));
21592159
}
2160+
void Unparse(const OmpDetachClause &x) { Walk(x.v); }
21602161
void Unparse(const OmpInReductionClause &x) {
21612162
Walk(std::get<OmpReductionOperator>(x.t));
21622163
Put(":");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! REQUIRES: openmp_runtime
2+
! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
3+
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 -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
@@ -135,6 +135,7 @@ def OMPC_Destroy : Clause<"destroy"> {
135135
}
136136
def OMPC_Detach : Clause<"detach"> {
137137
let clangClass = "OMPDetachClause";
138+
let flangClass = "OmpDetachClause";
138139
}
139140
def OMPC_Device : Clause<"device"> {
140141
let clangClass = "OMPDeviceClause";

0 commit comments

Comments
 (0)