Skip to content

Commit b9e3a76

Browse files
authored
[flang][mlir][llvm][OpenMP] Add lowering and translation support for mergeable clause on task (#114662)
Add FIR generation and LLVMIR translation support for mergeable clause on task construct. If mergeable clause is present on a task, the relevant flag in `ompt_task_flag_t` is set and passed to `__kmpc_omp_task_alloc`.
1 parent c0192a0 commit b9e3a76

File tree

8 files changed

+42
-44
lines changed

8 files changed

+42
-44
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,8 @@ static void genTaskClauses(lower::AbstractConverter &converter,
13491349
cp.processUntied(clauseOps);
13501350
// TODO Support delayed privatization.
13511351

1352-
cp.processTODO<clause::Affinity, clause::Detach, clause::InReduction,
1353-
clause::Mergeable>(loc, llvm::omp::Directive::OMPD_task);
1352+
cp.processTODO<clause::Affinity, clause::Detach, clause::InReduction>(
1353+
loc, llvm::omp::Directive::OMPD_task);
13541354
}
13551355

13561356
static void genTaskgroupClauses(lower::AbstractConverter &converter,

flang/test/Lower/OpenMP/Todo/task_mergeable.f90

Lines changed: 0 additions & 13 deletions
This file was deleted.

flang/test/Lower/OpenMP/task.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,11 @@ subroutine task_multiple_clauses()
234234
!CHECK: omp.terminator
235235
!$omp end task
236236
end subroutine task_multiple_clauses
237+
238+
subroutine task_mergeable()
239+
!CHECK: omp.task mergeable {
240+
!CHECK: omp.terminator
241+
!CHECK: }
242+
!$omp task mergeable
243+
!$omp end task
244+
end subroutine

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,12 +1262,12 @@ class OpenMPIRBuilder {
12621262
/// cannot be resumed until execution of the structured
12631263
/// block that is associated with the generated task is
12641264
/// completed.
1265-
InsertPointOrErrorTy createTask(const LocationDescription &Loc,
1266-
InsertPointTy AllocaIP,
1267-
BodyGenCallbackTy BodyGenCB, bool Tied = true,
1268-
Value *Final = nullptr,
1269-
Value *IfCondition = nullptr,
1270-
SmallVector<DependData> Dependencies = {});
1265+
/// \param Mergeable If the given task is `mergeable`
1266+
InsertPointOrErrorTy
1267+
createTask(const LocationDescription &Loc, InsertPointTy AllocaIP,
1268+
BodyGenCallbackTy BodyGenCB, bool Tied = true,
1269+
Value *Final = nullptr, Value *IfCondition = nullptr,
1270+
SmallVector<DependData> Dependencies = {}, bool Mergeable = false);
12711271

12721272
/// Generator for the taskgroup construct
12731273
///

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,11 +1815,10 @@ static Value *emitTaskDependencies(
18151815
return DepArray;
18161816
}
18171817

1818-
OpenMPIRBuilder::InsertPointOrErrorTy
1819-
OpenMPIRBuilder::createTask(const LocationDescription &Loc,
1820-
InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB,
1821-
bool Tied, Value *Final, Value *IfCondition,
1822-
SmallVector<DependData> Dependencies) {
1818+
OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
1819+
const LocationDescription &Loc, InsertPointTy AllocaIP,
1820+
BodyGenCallbackTy BodyGenCB, bool Tied, Value *Final, Value *IfCondition,
1821+
SmallVector<DependData> Dependencies, bool Mergeable) {
18231822

18241823
if (!updateToLocation(Loc))
18251824
return InsertPointTy();
@@ -1865,7 +1864,8 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
18651864
Builder, AllocaIP, ToBeDeleted, TaskAllocaIP, "global.tid", false));
18661865

18671866
OI.PostOutlineCB = [this, Ident, Tied, Final, IfCondition, Dependencies,
1868-
TaskAllocaBB, ToBeDeleted](Function &OutlinedFn) mutable {
1867+
Mergeable, TaskAllocaBB,
1868+
ToBeDeleted](Function &OutlinedFn) mutable {
18691869
// Replace the Stale CI by appropriate RTL function call.
18701870
assert(OutlinedFn.getNumUses() == 1 &&
18711871
"there must be a single user for the outlined function");
@@ -1890,6 +1890,8 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
18901890
// Task is untied iff (Flags & 1) == 0.
18911891
// Task is final iff (Flags & 2) == 2.
18921892
// Task is not final iff (Flags & 2) == 0.
1893+
// Task is mergeable iff (Flags & 4) == 4.
1894+
// Task is not mergeable iff (Flags & 4) == 0.
18931895
// TODO: Handle the other flags.
18941896
Value *Flags = Builder.getInt32(Tied);
18951897
if (Final) {
@@ -1898,6 +1900,9 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
18981900
Flags = Builder.CreateOr(FinalFlag, Flags);
18991901
}
19001902

1903+
if (Mergeable)
1904+
Flags = Builder.CreateOr(Builder.getInt32(4), Flags);
1905+
19011906
// Argument - `sizeof_kmp_task_t` (TaskSize)
19021907
// Tasksize refers to the size in bytes of kmp_task_t data structure
19031908
// including private vars accessed in task.

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ static LogicalResult checkImplementationStatus(Operation &op) {
191191
if (!op.getLinearVars().empty() || !op.getLinearStepVars().empty())
192192
result = todo("linear");
193193
};
194-
auto checkMergeable = [&todo](auto op, LogicalResult &result) {
195-
if (op.getMergeable())
196-
result = todo("mergeable");
197-
};
198194
auto checkNontemporal = [&todo](auto op, LogicalResult &result) {
199195
if (!op.getNontemporalVars().empty())
200196
result = todo("nontemporal");
@@ -257,7 +253,6 @@ static LogicalResult checkImplementationStatus(Operation &op) {
257253
.Case([&](omp::TaskOp op) {
258254
checkAllocate(op, result);
259255
checkInReduction(op, result);
260-
checkMergeable(op, result);
261256
checkPriority(op, result);
262257
checkUntied(op, result);
263258
})
@@ -1662,7 +1657,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
16621657
moduleTranslation.getOpenMPBuilder()->createTask(
16631658
ompLoc, allocaIP, bodyCB, !taskOp.getUntied(),
16641659
moduleTranslation.lookupValue(taskOp.getFinal()),
1665-
moduleTranslation.lookupValue(taskOp.getIfExpr()), dds);
1660+
moduleTranslation.lookupValue(taskOp.getIfExpr()), dds,
1661+
taskOp.getMergeable());
16661662

16671663
if (failed(handleError(afterIP, *taskOp)))
16681664
return failure();

mlir/test/Target/LLVMIR/openmp-llvm.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,19 @@ module attributes {omp.is_target_device = true} {
30033003

30043004
// -----
30053005

3006+
// Third argument is 5: essentially (4 || 1)
3007+
// signifying this task is TIED and MERGEABLE
3008+
3009+
// CHECK: {{.*}} = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 %omp_global_thread_num, i32 5, i64 40, i64 0, ptr @omp_task_mergeable..omp_par)
3010+
llvm.func @omp_task_mergeable() {
3011+
omp.task mergeable {
3012+
omp.terminator
3013+
}
3014+
llvm.return
3015+
}
3016+
3017+
// -----
3018+
30063019
llvm.func external @foo_before() -> ()
30073020
llvm.func external @foo() -> ()
30083021
llvm.func external @foo_after() -> ()

mlir/test/Target/LLVMIR/openmp-todo.mlir

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,6 @@ llvm.func @task_in_reduction(%x : !llvm.ptr) {
447447

448448
// -----
449449

450-
llvm.func @task_mergeable() {
451-
// expected-error@below {{not yet implemented: Unhandled clause mergeable in omp.task operation}}
452-
// expected-error@below {{LLVM Translation failed for operation: omp.task}}
453-
omp.task mergeable {
454-
omp.terminator
455-
}
456-
llvm.return
457-
}
458-
459-
// -----
460-
461450
llvm.func @task_priority(%x : i32) {
462451
// expected-error@below {{not yet implemented: Unhandled clause priority in omp.task operation}}
463452
// expected-error@below {{LLVM Translation failed for operation: omp.task}}

0 commit comments

Comments
 (0)