Skip to content

Commit 0bcef33

Browse files
committed
[flang] Add lowering support for task detach
1 parent 9eb4056 commit 0bcef33

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ bool ClauseProcessor::processPriority(
458458
return false;
459459
}
460460

461+
bool ClauseProcessor::processDetach(mlir::omp::DetachClauseOps &result) const {
462+
if (auto *clause = findUniqueClause<omp::clause::Detach>()) {
463+
semantics::Symbol *sym = clause->v.sym();
464+
mlir::Value symVal = converter.getSymbolAddress(*sym);
465+
result.eventHandle = symVal;
466+
return true;
467+
}
468+
return false;
469+
}
470+
461471
bool ClauseProcessor::processProcBind(
462472
mlir::omp::ProcBindClauseOps &result) const {
463473
if (auto *clause = findUniqueClause<omp::clause::ProcBind>()) {

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ClauseProcessor {
9090
mlir::omp::ThreadLimitClauseOps &result) const;
9191
bool processUntied(mlir::omp::UntiedClauseOps &result) const;
9292

93+
bool processDetach(mlir::omp::DetachClauseOps &result) const;
9394
// 'Repeatable' clauses: They can appear multiple times in the clause list.
9495
bool processAligned(mlir::omp::AlignedClauseOps &result) const;
9596
bool processAllocate(mlir::omp::AllocateClauseOps &result) const;

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,10 @@ static void genTaskClauses(lower::AbstractConverter &converter,
12611261
cp.processMergeable(clauseOps);
12621262
cp.processPriority(stmtCtx, clauseOps);
12631263
cp.processUntied(clauseOps);
1264+
cp.processDetach(clauseOps);
12641265
// TODO Support delayed privatization.
12651266

1266-
cp.processTODO<clause::Affinity, clause::Detach, clause::InReduction>(
1267+
cp.processTODO<clause::Affinity, clause::InReduction>(
12671268
loc, llvm::omp::Directive::OMPD_task);
12681269
}
12691270

@@ -2869,7 +2870,8 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
28692870
!std::holds_alternative<clause::UseDevicePtr>(clause.u) &&
28702871
!std::holds_alternative<clause::InReduction>(clause.u) &&
28712872
!std::holds_alternative<clause::Mergeable>(clause.u) &&
2872-
!std::holds_alternative<clause::TaskReduction>(clause.u)) {
2873+
!std::holds_alternative<clause::TaskReduction>(clause.u) &&
2874+
!std::holds_alternative<clause::Detach>(clause.u)) {
28732875
std::string name =
28742876
parser::ToUpperCaseLetters(llvm::omp::getOpenMPClauseName(clause.id));
28752877
TODO(clauseLocation, name + " clause is not implemented yet");

flang/test/Lower/OpenMP/Todo/task_detach.f90 renamed to flang/test/Lower/OpenMP/task_detach.f90

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
! REQUIRES: openmp_runtime
2-
! RUN: %not_todo_cmd bbc -emit-fir %openmp_flags -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
3-
! RUN: %not_todo_cmd %flang_fc1 -emit-fir %openmp_flags -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
2+
! RUN: %flang_fc1 -emit-fir %openmp_flags -fopenmp -fopenmp-version=50 -o - %s | FileCheck %s
43

54
!===============================================================================
65
! `detach` clause
76
!===============================================================================
87

9-
! CHECK: not yet implemented: DETACH clause is not implemented yet
8+
!CHECK: omp.task detach(%[[EVENT_HANDLE:.*]] : !fir.ref<i64>) {
9+
!CHECK: fir.call @_QPfoo() fastmath<contract> : () -> ()
10+
!CHECK: omp.terminator
11+
!CHECK: }
1012
subroutine omp_task_detach()
1113
use omp_lib
1214
integer (kind=omp_event_handle_kind) :: event

0 commit comments

Comments
 (0)