Skip to content

Commit 94c9964

Browse files
committed
[flang][mlir][llvm][OpenMP] Add lowering and translation support for mergeable clause on task
1 parent 0653698 commit 94c9964

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
@@ -1336,8 +1336,8 @@ static void genTaskClauses(lower::AbstractConverter &converter,
13361336
cp.processUntied(clauseOps);
13371337
// TODO Support delayed privatization.
13381338

1339-
cp.processTODO<clause::Affinity, clause::Detach, clause::InReduction,
1340-
clause::Mergeable>(loc, llvm::omp::Directive::OMPD_task);
1339+
cp.processTODO<clause::Affinity, clause::Detach, clause::InReduction>(
1340+
loc, llvm::omp::Directive::OMPD_task);
13411341
}
13421342

13431343
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
@@ -245,3 +245,11 @@ subroutine task_multiple_clauses()
245245
!CHECK: omp.terminator
246246
!$omp end task
247247
end subroutine task_multiple_clauses
248+
249+
subroutine task_mergeable()
250+
!CHECK: omp.task mergeable {
251+
!CHECK: omp.terminator
252+
!CHECK: }
253+
!$omp task mergeable
254+
!$omp end task
255+
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
@@ -1816,11 +1816,10 @@ static Value *emitTaskDependencies(
18161816
return DepArray;
18171817
}
18181818

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

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

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

1904+
if (Mergeable)
1905+
Flags = Builder.CreateOr(Builder.getInt32(4), Flags);
1906+
19021907
// Argument - `sizeof_kmp_task_t` (TaskSize)
19031908
// Tasksize refers to the size in bytes of kmp_task_t data structure
19041909
// 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
@@ -189,10 +189,6 @@ static LogicalResult checkImplementationStatus(Operation &op) {
189189
if (!op.getLinearVars().empty() || !op.getLinearStepVars().empty())
190190
result = todo("linear");
191191
};
192-
auto checkMergeable = [&todo](auto op, LogicalResult &result) {
193-
if (op.getMergeable())
194-
result = todo("mergeable");
195-
};
196192
auto checkNontemporal = [&todo](auto op, LogicalResult &result) {
197193
if (!op.getNontemporalVars().empty())
198194
result = todo("nontemporal");
@@ -255,7 +251,6 @@ static LogicalResult checkImplementationStatus(Operation &op) {
255251
.Case([&](omp::TaskOp op) {
256252
checkAllocate(op, result);
257253
checkInReduction(op, result);
258-
checkMergeable(op, result);
259254
checkPriority(op, result);
260255
checkPrivate(op, result);
261256
checkUntied(op, result);
@@ -1507,7 +1502,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
15071502
moduleTranslation.getOpenMPBuilder()->createTask(
15081503
ompLoc, allocaIP, bodyCB, !taskOp.getUntied(),
15091504
moduleTranslation.lookupValue(taskOp.getFinal()),
1510-
moduleTranslation.lookupValue(taskOp.getIfExpr()), dds);
1505+
moduleTranslation.lookupValue(taskOp.getIfExpr()), dds,
1506+
taskOp.getMergeable());
15111507

15121508
if (failed(handleError(afterIP, *taskOp)))
15131509
return failure();

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

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

29532953
// -----
29542954

2955+
// Third argument is 5: essentially (4 || 1)
2956+
// signifying this task is TIED and MERGEABLE
2957+
2958+
// 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)
2959+
llvm.func @omp_task_mergeable() {
2960+
omp.task mergeable {
2961+
omp.terminator
2962+
}
2963+
llvm.return
2964+
}
2965+
2966+
// -----
2967+
29552968
llvm.func external @foo_before() -> ()
29562969
llvm.func external @foo() -> ()
29572970
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 {{mergeable clause not yet supported}}
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 {{priority clause not yet supported}}
463452
// expected-error@below {{LLVM Translation failed for operation: omp.task}}

0 commit comments

Comments
 (0)