[flang-commits] [flang] [llvm] [mlir] [Flang][OpenMP] Implement DEPEND clause for TASKWAIT directive (PR #193568)
Phoebe Linck via flang-commits
flang-commits at lists.llvm.org
Mon Jun 8 10:55:54 PDT 2026
https://github.com/phi-bee updated https://github.com/llvm/llvm-project/pull/193568
>From f604e4ab4c427a15c3430b096d2227e714fc6489 Mon Sep 17 00:00:00 2001
From: Phoebe Linck <phoebe.linck at hpe.com>
Date: Thu, 16 Apr 2026 21:58:27 -0500
Subject: [PATCH 1/7] [Flang][OpenMP] Implement depend clause for taskwait
directive
---
flang/lib/Lower/OpenMP/OpenMP.cpp | 6 +-
.../Lower/OpenMP/Todo/taskwait-depend.f90 | 10 ----
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 16 +++--
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 59 +++++++++++++------
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 12 ++--
.../OpenMP/OpenMPToLLVMIRTranslation.cpp | 15 +++--
6 files changed, 72 insertions(+), 46 deletions(-)
delete mode 100644 flang/test/Lower/OpenMP/Todo/taskwait-depend.f90
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 5cdb54a07fecd..fd9835d3b3400 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1895,8 +1895,10 @@ static void genTaskwaitClauses(lower::AbstractConverter &converter,
const List<Clause> &clauses, mlir::Location loc,
mlir::omp::TaskwaitOperands &clauseOps) {
ClauseProcessor cp(converter, semaCtx, clauses);
- cp.processTODO<clause::Depend, clause::Nowait>(
- loc, llvm::omp::Directive::OMPD_taskwait);
+ lower::StatementContext stmtCtx;
+ lower::SymMap &symTable = converter.getSymbolMap();
+ cp.processDepend(symTable, stmtCtx, clauseOps);
+ cp.processTODO<clause::Nowait>(loc, llvm::omp::Directive::OMPD_taskwait);
}
static void genWorkshareClauses(lower::AbstractConverter &converter,
diff --git a/flang/test/Lower/OpenMP/Todo/taskwait-depend.f90 b/flang/test/Lower/OpenMP/Todo/taskwait-depend.f90
deleted file mode 100644
index d1f953be8802f..0000000000000
--- a/flang/test/Lower/OpenMP/Todo/taskwait-depend.f90
+++ /dev/null
@@ -1,10 +0,0 @@
-! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s -fopenmp-version=50 2>&1 | FileCheck %s
-! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s -fopenmp-version=50 2>&1 | FileCheck %s
-
-! CHECK: not yet implemented: Unhandled clause DEPEND in TASKWAIT construct
-subroutine omp_tw_depend
- integer :: res
- !$omp taskwait depend(out: res)
- res = res + 1
-end subroutine omp_tw_depend
-
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index dbd8f0c6b8927..f47dec2ba4333 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1490,11 +1490,6 @@ class OpenMPIRBuilder {
/// \param Loc The location where the flush directive was encountered
LLVM_ABI void createFlush(const LocationDescription &Loc);
- /// Generator for '#omp taskwait'
- ///
- /// \param Loc The location where the taskwait directive was encountered.
- LLVM_ABI void createTaskwait(const LocationDescription &Loc);
-
/// Generator for '#omp taskyield'
///
/// \param Loc The location where the taskyield directive was encountered.
@@ -1533,7 +1528,16 @@ class OpenMPIRBuilder {
LLVM_ABI void emitTaskDependency(IRBuilderBase &Builder, Value *Entry,
const DependData &Dep);
- /// Return the LLVM struct type matching runtime `kmp_task_affinity_info_t`.
+
+ /// Generator for '#omp taskwait'
+ ///
+ /// \param Loc The location where the taskwait directive was encountered.
+ /// \param Dependencies Vector of DependData objects holding information of
+ /// dependencies as specified by the 'depend' clause.
+ LLVM_ABI void createTaskwait(const LocationDescription &Loc,
+ SmallVector<DependData> Dependencies = {});
+
+ /// Return the LLVM struct type matching runtime `kmp_task_affinity_info_t`.
/// `{ kmp_intptr_t base_addr; size_t len; flags (bitfield storage as i32) }`
LLVM_ABI llvm::StructType *getKmpTaskAffinityInfoTy();
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 407ffcf2826df..05a9e2cfbf84c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1928,25 +1928,6 @@ void OpenMPIRBuilder::createFlush(const LocationDescription &Loc) {
emitFlush(Loc);
}
-void OpenMPIRBuilder::emitTaskwaitImpl(const LocationDescription &Loc) {
- // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32
- // global_tid);
- uint32_t SrcLocStrSize;
- Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
- Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
- Value *Args[] = {Ident, getOrCreateThreadID(Ident)};
-
- // Ignore return result until untied tasks are supported.
- createRuntimeFunctionCall(
- getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_taskwait), Args);
-}
-
-void OpenMPIRBuilder::createTaskwait(const LocationDescription &Loc) {
- if (!updateToLocation(Loc))
- return;
- emitTaskwaitImpl(Loc);
-}
-
void OpenMPIRBuilder::emitTaskyieldImpl(const LocationDescription &Loc) {
// Build call __kmpc_omp_taskyield(loc, thread_id, 0);
uint32_t SrcLocStrSize;
@@ -2037,6 +2018,46 @@ static Value *emitTaskDependencies(
return DepArray;
}
+void OpenMPIRBuilder::emitTaskwaitImpl(const LocationDescription &Loc) {
+ // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32
+ // global_tid);
+ uint32_t SrcLocStrSize;
+ Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
+ Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
+ Value *Args[] = {Ident, getOrCreateThreadID(Ident)};
+
+ // Ignore return result until untied tasks are supported.
+ createRuntimeFunctionCall(
+ getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_taskwait), Args);
+}
+
+void OpenMPIRBuilder::createTaskwait(const LocationDescription &Loc,
+ SmallVector<DependData> Dependencies) {
+ if (!updateToLocation(Loc))
+ return;
+
+ if (Dependencies.size()) {
+ uint32_t SrcLocStrSize;
+ Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
+ Value *DepArray = emitTaskDependencies(*this, Dependencies);
+ Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
+ Value *Args[] = {
+ Ident,
+ getOrCreateThreadID(Ident),
+ Builder.getInt32(Dependencies.size()),
+ DepArray,
+ ConstantInt::get(Builder.getInt32Ty(), 0),
+ ConstantPointerNull::get(PointerType::getUnqual(M.getContext())),
+ ConstantInt::get(Builder.getInt32Ty(), false)};
+ createRuntimeFunctionCall(
+ getOrCreateRuntimeFunctionPtr(
+ omp::RuntimeFunction::OMPRTL___kmpc_omp_taskwait_deps_51),
+ Args);
+ } else {
+ emitTaskwaitImpl(Loc);
+ }
+}
+
/// Create the task duplication function passed to kmpc_taskloop.
Expected<Value *> OpenMPIRBuilder::createTaskDuplicationFunction(
Type *PrivatesTy, int32_t PrivatesIndex, TaskDupCallbackTy DupCB) {
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 691793b50d33d..08096f791f640 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -4267,10 +4267,14 @@ LogicalResult OrderedRegionOp::verify() { return verifyOrderedParent(**this); }
void TaskwaitOp::build(OpBuilder &builder, OperationState &state,
const TaskwaitOperands &clauses) {
- // TODO Store clauses in op: dependKinds, dependVars, nowait.
- TaskwaitOp::build(builder, state, /*depend_kinds=*/nullptr,
- /*depend_vars=*/{}, /*depend_iterated_kinds=*/nullptr,
- /*depend_iterated=*/{}, /*nowait=*/nullptr);
+ // TODO Store clauses in op: depend_iterated_kinds, depend_iterated, nowait.
+ MLIRContext *ctx = builder.getContext();
+ TaskwaitOp::build(builder, state,
+ /*depend_kinds=*/makeArrayAttr(ctx, clauses.dependKinds),
+ /*depend_vars=*/clauses.dependVars,
+ /*depend_iterated_kinds=*/nullptr,
+ /*depend_iterated=*/{},
+ /*nowait=*/nullptr);
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index f9aeb483651f4..f1e0cb4d661bb 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -412,10 +412,7 @@ static LogicalResult checkImplementationStatus(Operation &op) {
checkAllocate(op, result);
checkTaskReduction(op, result);
})
- .Case([&](omp::TaskwaitOp op) {
- checkDepend(op, result);
- checkNowait(op, result);
- })
+ .Case([&](omp::TaskwaitOp op) { checkNowait(op, result); })
.Case([&](omp::TaskloopContextOp op) {
checkAllocate(op, result);
checkInReduction(op, result);
@@ -3482,7 +3479,15 @@ convertOmpTaskwaitOp(omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder,
if (failed(checkImplementationStatus(*twOp)))
return failure();
- moduleTranslation.getOpenMPBuilder()->createTaskwait(builder.saveIP());
+ llvm::OpenMPIRBuilder::DependenciesInfo dds;
+ if (failed(buildDependData(
+ twOp.getDependVars(), twOp.getDependKinds(), twOp.getDependIterated(),
+ twOp.getDependIteratedKinds(), builder, moduleTranslation, dds))) {
+ return failure();
+ }
+
+ moduleTranslation.getOpenMPBuilder()->createTaskwait(builder.saveIP(),
+ dds.Deps);
return success();
}
>From 43a8ae43a52bb5dcc6b4a6c6aee2f795195557d3 Mon Sep 17 00:00:00 2001
From: Phoebe Linck <phoebe.linck at hpe.com>
Date: Wed, 22 Apr 2026 14:15:48 -0500
Subject: [PATCH 2/7] fix formatting error
---
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index f47dec2ba4333..1c6a349aca6a7 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1528,7 +1528,6 @@ class OpenMPIRBuilder {
LLVM_ABI void emitTaskDependency(IRBuilderBase &Builder, Value *Entry,
const DependData &Dep);
-
/// Generator for '#omp taskwait'
///
/// \param Loc The location where the taskwait directive was encountered.
>From f70f9f0d7fc3135ce8c6b782bc972e45cf1f8572 Mon Sep 17 00:00:00 2001
From: Phoebe Linck <phoebe.linck at hpe.com>
Date: Wed, 6 May 2026 12:51:56 -0500
Subject: [PATCH 3/7] Add tests
---
flang/test/Lower/OpenMP/taskwait-depend.f90 | 8 ++++++++
mlir/test/Target/LLVMIR/openmp-taskwait-depend.mlir | 12 ++++++++++++
2 files changed, 20 insertions(+)
create mode 100644 flang/test/Lower/OpenMP/taskwait-depend.f90
create mode 100644 mlir/test/Target/LLVMIR/openmp-taskwait-depend.mlir
diff --git a/flang/test/Lower/OpenMP/taskwait-depend.f90 b/flang/test/Lower/OpenMP/taskwait-depend.f90
new file mode 100644
index 0000000000000..21e3423fa4ae7
--- /dev/null
+++ b/flang/test/Lower/OpenMP/taskwait-depend.f90
@@ -0,0 +1,8 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
+
+!CHECK-LABEL: @_QPomp_taskwait_depend
+subroutine omp_taskwait_depend
+ integer :: x
+ !CHECK: omp.taskwait depend(taskdependin -> %{{.+}} : !fir.ref<i32>)
+ !$omp taskwait depend(in: x)
+end subroutine omp_taskwait_depend
diff --git a/mlir/test/Target/LLVMIR/openmp-taskwait-depend.mlir b/mlir/test/Target/LLVMIR/openmp-taskwait-depend.mlir
new file mode 100644
index 0000000000000..7829a0dde4d2f
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/openmp-taskwait-depend.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-translate --mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+llvm.func @taskwait_depend(%x: !llvm.ptr) {
+ omp.taskwait depend(taskdependout -> %x : !llvm.ptr)
+ llvm.return
+}
+
+// CHECK-LABEL: define void @taskwait_depend
+// CHECK-SAME: (ptr[[xaddr:.+]])
+// CHECK: %[[dep_arr_addr:.+]] = alloca [1 x %struct.kmp_dep_info], align 8
+// CHECK: %[[omp_global_thread_num:.+]] = call i32 @__kmpc_global_thread_num({{.+}})
+// CHECK: call void @__kmpc_omp_taskwait_deps_51(ptr @{{.+}}, i32 %[[omp_global_thread_num]], i32 1, ptr %[[dep_arr_addr]], i32 0, ptr null, i32 0)
>From d5a860e03691cc20ae3451c867b1dcb9a8e0a647 Mon Sep 17 00:00:00 2001
From: Phoebe Linck <phoebe.linck at hpe.com>
Date: Wed, 6 May 2026 12:52:52 -0500
Subject: [PATCH 4/7] Remove TODO test
---
mlir/test/Target/LLVMIR/openmp-todo.mlir | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/mlir/test/Target/LLVMIR/openmp-todo.mlir b/mlir/test/Target/LLVMIR/openmp-todo.mlir
index af5da3dc8c3a4..4c1db53c83224 100644
--- a/mlir/test/Target/LLVMIR/openmp-todo.mlir
+++ b/mlir/test/Target/LLVMIR/openmp-todo.mlir
@@ -366,17 +366,6 @@ llvm.func @taskloop_reduction(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr)
// -----
-llvm.func @taskwait_depend(%x: !llvm.ptr) {
- // expected-error at below {{not yet implemented: Unhandled clause depend in omp.taskwait operation}}
- // expected-error at below {{LLVM Translation failed for operation: omp.taskwait}}
- omp.taskwait depend(taskdependin -> %x : !llvm.ptr) {
- omp.terminator
- }
- llvm.return
-}
-
-// -----
-
llvm.func @taskwait_nowait() {
// expected-error at below {{not yet implemented: Unhandled clause nowait in omp.taskwait operation}}
// expected-error at below {{LLVM Translation failed for operation: omp.taskwait}}
>From 1acf1f2693ca660806b4f91dd29579e4346715f4 Mon Sep 17 00:00:00 2001
From: Phoebe Linck <phoebe.linck at hpe.com>
Date: Wed, 6 May 2026 12:53:19 -0500
Subject: [PATCH 5/7] Fix crash in mlir-translate
---
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 05a9e2cfbf84c..9d63bc5f2c2a9 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2037,9 +2037,19 @@ void OpenMPIRBuilder::createTaskwait(const LocationDescription &Loc,
return;
if (Dependencies.size()) {
+ Builder.SetInsertPoint(
+ &Builder.GetInsertBlock()->getParent()->getEntryBlock());
+
+ Value *DepArray = nullptr;
+ Type *DepArrayTy = ArrayType::get(DependInfo, Dependencies.size());
+ DepArray = Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr");
+ for (const auto &[DepIdx, Dep] : enumerate(Dependencies)) {
+ Value *Base =
+ Builder.CreateConstInBoundsGEP2_64(DepArrayTy, DepArray, 0, DepIdx);
+ this->emitTaskDependency(Builder, Base, Dep);
+ }
uint32_t SrcLocStrSize;
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
- Value *DepArray = emitTaskDependencies(*this, Dependencies);
Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
Value *Args[] = {
Ident,
>From 1f60306ce2dd9cbb0941c08bbbbc90813b539587 Mon Sep 17 00:00:00 2001
From: Phoebe Linck <phoebe.linck at hpe.com>
Date: Mon, 18 May 2026 16:20:47 -0500
Subject: [PATCH 6/7] Fix crash, cont.
---
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h | 2 +-
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 11 ++++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 1c6a349aca6a7..9d92eef75ac27 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1534,7 +1534,7 @@ class OpenMPIRBuilder {
/// \param Dependencies Vector of DependData objects holding information of
/// dependencies as specified by the 'depend' clause.
LLVM_ABI void createTaskwait(const LocationDescription &Loc,
- SmallVector<DependData> Dependencies = {});
+ ArrayRef<DependData> Dependencies = {});
/// Return the LLVM struct type matching runtime `kmp_task_affinity_info_t`.
/// `{ kmp_intptr_t base_addr; size_t len; flags (bitfield storage as i32) }`
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 9d63bc5f2c2a9..993eeafb3ddf1 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2032,17 +2032,22 @@ void OpenMPIRBuilder::emitTaskwaitImpl(const LocationDescription &Loc) {
}
void OpenMPIRBuilder::createTaskwait(const LocationDescription &Loc,
- SmallVector<DependData> Dependencies) {
+ ArrayRef<DependData> Dependencies) {
if (!updateToLocation(Loc))
return;
if (Dependencies.size()) {
- Builder.SetInsertPoint(
- &Builder.GetInsertBlock()->getParent()->getEntryBlock());
+ InsertPointTy OldIP = Builder.saveIP();
+ BasicBlock &entryBB =
+ Builder.GetInsertBlock()->getParent()->getEntryBlock();
+ Builder.SetInsertPoint(&entryBB, entryBB.getFirstInsertionPt());
Value *DepArray = nullptr;
Type *DepArrayTy = ArrayType::get(DependInfo, Dependencies.size());
DepArray = Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr");
+
+ Builder.restoreIP(OldIP);
+
for (const auto &[DepIdx, Dep] : enumerate(Dependencies)) {
Value *Base =
Builder.CreateConstInBoundsGEP2_64(DepArrayTy, DepArray, 0, DepIdx);
>From 2dc19c3c7c09d1302820c4d44b233b22022ff222 Mon Sep 17 00:00:00 2001
From: Phoebe Linck <phoebe.linck at hpe.com>
Date: Mon, 8 Jun 2026 12:40:51 -0500
Subject: [PATCH 7/7] Fix depend iterator bug
---
.../llvm/Frontend/OpenMP/OMPIRBuilder.h | 5 ++---
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 22 +++++++++++++------
.../OpenMP/OpenMPToLLVMIRTranslation.cpp | 3 +--
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 9d92eef75ac27..7a9ec944d0670 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1531,10 +1531,9 @@ class OpenMPIRBuilder {
/// Generator for '#omp taskwait'
///
/// \param Loc The location where the taskwait directive was encountered.
- /// \param Dependencies Vector of DependData objects holding information of
- /// dependencies as specified by the 'depend' clause.
+ /// \param Dependencies dependencies as specified by the 'depend' clause.
LLVM_ABI void createTaskwait(const LocationDescription &Loc,
- ArrayRef<DependData> Dependencies = {});
+ DependenciesInfo Dependencies = {});
/// Return the LLVM struct type matching runtime `kmp_task_affinity_info_t`.
/// `{ kmp_intptr_t base_addr; size_t len; flags (bitfield storage as i32) }`
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 993eeafb3ddf1..92d8790bc1acb 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2032,34 +2032,42 @@ void OpenMPIRBuilder::emitTaskwaitImpl(const LocationDescription &Loc) {
}
void OpenMPIRBuilder::createTaskwait(const LocationDescription &Loc,
- ArrayRef<DependData> Dependencies) {
+ DependenciesInfo Dependencies) {
if (!updateToLocation(Loc))
return;
- if (Dependencies.size()) {
+ Value *DepArray = nullptr;
+ Type *DepArrayTy = nullptr;
+ Value *NumDeps = nullptr;
+ if (Dependencies.DepArray) {
+ DepArray = Dependencies.DepArray;
+ NumDeps = Dependencies.NumDeps;
+ } else if (!Dependencies.Deps.empty()) {
InsertPointTy OldIP = Builder.saveIP();
BasicBlock &entryBB =
Builder.GetInsertBlock()->getParent()->getEntryBlock();
Builder.SetInsertPoint(&entryBB, entryBB.getFirstInsertionPt());
- Value *DepArray = nullptr;
- Type *DepArrayTy = ArrayType::get(DependInfo, Dependencies.size());
+ DepArrayTy = ArrayType::get(DependInfo, Dependencies.Deps.size());
DepArray = Builder.CreateAlloca(DepArrayTy, nullptr, ".dep.arr.addr");
+ NumDeps = Builder.getInt32(Dependencies.Deps.size());
Builder.restoreIP(OldIP);
-
- for (const auto &[DepIdx, Dep] : enumerate(Dependencies)) {
+ for (const auto &[DepIdx, Dep] : enumerate(Dependencies.Deps)) {
Value *Base =
Builder.CreateConstInBoundsGEP2_64(DepArrayTy, DepArray, 0, DepIdx);
this->emitTaskDependency(Builder, Base, Dep);
}
+ }
+
+ if (DepArray) {
uint32_t SrcLocStrSize;
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc, SrcLocStrSize);
Value *Ident = getOrCreateIdent(SrcLocStr, SrcLocStrSize);
Value *Args[] = {
Ident,
getOrCreateThreadID(Ident),
- Builder.getInt32(Dependencies.size()),
+ NumDeps,
DepArray,
ConstantInt::get(Builder.getInt32Ty(), 0),
ConstantPointerNull::get(PointerType::getUnqual(M.getContext())),
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index f1e0cb4d661bb..11316e1ce87c7 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -3486,8 +3486,7 @@ convertOmpTaskwaitOp(omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder,
return failure();
}
- moduleTranslation.getOpenMPBuilder()->createTaskwait(builder.saveIP(),
- dds.Deps);
+ moduleTranslation.getOpenMPBuilder()->createTaskwait(builder.saveIP(), dds);
return success();
}
More information about the flang-commits
mailing list