Skip to content

Commit 13cd881

Browse files
[mlir][OpenMP] - Honor dependencies in code-generation of the if clause in omp.task correctly (llvm#90891)
This patch fixes the code generation of the if clause, specifically when the condition evaluates to false and when the task directive has the depend clause on it. When the if clause of a task construct evaluates to false, then the task is an undeferred task. This undeferred task still has to honor dependencies. Previously, the OpenMPIRbuilder didn't honor dependencies. This patch fixes that. Fixes llvm#90869
1 parent 1a25b72 commit 13cd881

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,9 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
18701870
// call @__kmpc_omp_task(...)
18711871
// br label %exit
18721872
// else:
1873+
// ;; Wait for resolution of dependencies, if any, before
1874+
// ;; beginning the task
1875+
// call @__kmpc_omp_wait_deps(...)
18731876
// call @__kmpc_omp_task_begin_if0(...)
18741877
// call @outlined_fn(...)
18751878
// call @__kmpc_omp_task_complete_if0(...)
@@ -1887,6 +1890,16 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
18871890
SplitBlockAndInsertIfThenElse(IfCondition, IfTerminator, &ThenTI,
18881891
&ElseTI);
18891892
Builder.SetInsertPoint(ElseTI);
1893+
1894+
if (Dependencies.size()) {
1895+
Function *TaskWaitFn =
1896+
getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_wait_deps);
1897+
Builder.CreateCall(
1898+
TaskWaitFn,
1899+
{Ident, ThreadID, Builder.getInt32(Dependencies.size()), DepArray,
1900+
ConstantInt::get(Builder.getInt32Ty(), 0),
1901+
ConstantPointerNull::get(PointerType::getUnqual(M.getContext()))});
1902+
}
18901903
Function *TaskBeginFn =
18911904
getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_begin_if0);
18921905
Function *TaskCompleteFn =
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
2+
3+
llvm.func @foo_(%arg0: !llvm.ptr {fir.bindc_name = "n"}, %arg1: !llvm.ptr {fir.bindc_name = "r"}) attributes {fir.internal_name = "_QPfoo"} {
4+
%0 = llvm.mlir.constant(false) : i1
5+
omp.task if(%0) depend(taskdependin -> %arg0 : !llvm.ptr) {
6+
%1 = llvm.load %arg0 : !llvm.ptr -> i32
7+
llvm.store %1, %arg1 : i32, !llvm.ptr
8+
omp.terminator
9+
}
10+
llvm.return
11+
}
12+
13+
// CHECK: call void @__kmpc_omp_wait_deps
14+
// CHECK-NEXT: call void @__kmpc_omp_task_begin_if0
15+
// CHECK-NEXT: call void @foo_..omp_par
16+
// CHECK-NEXT: call void @__kmpc_omp_task_complete_if0
17+

0 commit comments

Comments
 (0)