Skip to content

[flang][OpenMP] Add parsing support for Task detach #112312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,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)
Expand Down
5 changes: 5 additions & 0 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,11 @@ 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);
};

// OMP 5.0 2.19.5.6 in_reduction-clause -> IN_REDUCTION (reduction-identifier:
// variable-name-list)
struct OmpInReductionClause {
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Lower/OpenMP/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ Destroy make(const parser::OmpClause::Destroy &inp,

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

Device make(const parser::OmpClause::Device &inp,
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ TYPE_CONTEXT_PARSER("Omp LINEAR clause"_en_US,
construct<OmpLinearClause>(construct<OmpLinearClause::WithoutModifier>(
nonemptyList(name), maybe(":" >> scalarIntConstantExpr)))))

// OpenMPv5.2 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)))
Expand Down Expand Up @@ -529,6 +532,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>{}))) ||
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,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(":");
Expand Down
16 changes: 16 additions & 0 deletions flang/test/Lower/OpenMP/Todo/task_detach.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! REQUIRES: openmp_runtime
! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s

!===============================================================================
! `detach` clause
!===============================================================================

! CHECK: not yet implemented: OpenMP Block construct clause
subroutine omp_task_detach()
use omp_lib
integer (kind=omp_event_handle_kind) :: event
!$omp task detach(event)
call foo()
!$omp end task
end subroutine omp_task_detach
17 changes: 17 additions & 0 deletions flang/test/Parser/OpenMP/task.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
! REQUIRES: openmp_runtime
! 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use omp_lib needs ! REQUIRES: openmp_runtime, to avoid errors when OpenMP runtime is not available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

implicit none
integer(kind=omp_event_handle_kind) :: event
!$omp task detach(event)
!$omp end task
end subroutine
1 change: 1 addition & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMP.td
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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";
Expand Down
Loading