aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranav Bhandarkar <pranav.bhandarkar@amd.com>2024-05-13 08:54:23 -0500
committerGitHub <noreply@github.com>2024-05-13 08:54:23 -0500
commit13cd88108f00fc97bcd1e4eb7cc9e4e388928677 (patch)
tree3dfdb00aa2777dd557344fd252c7a9a536992888
parent1a25b723628e439d62dfb28ca5fa52e4b2a78e5a (diff)
downloadllvm-13cd88108f00fc97bcd1e4eb7cc9e4e388928677.zip
llvm-13cd88108f00fc97bcd1e4eb7cc9e4e388928677.tar.gz
llvm-13cd88108f00fc97bcd1e4eb7cc9e4e388928677.tar.bz2
[mlir][OpenMP] - Honor dependencies in code-generation of the if clause in `omp.task` correctly (#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 https://github.com/llvm/llvm-project/issues/90869
-rw-r--r--llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp13
-rw-r--r--mlir/test/Target/LLVMIR/omptask_if_false.mlir17
2 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 42ea209..391a494 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1870,6 +1870,9 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
// call @__kmpc_omp_task(...)
// br label %exit
// else:
+ // ;; Wait for resolution of dependencies, if any, before
+ // ;; beginning the task
+ // call @__kmpc_omp_wait_deps(...)
// call @__kmpc_omp_task_begin_if0(...)
// call @outlined_fn(...)
// call @__kmpc_omp_task_complete_if0(...)
@@ -1887,6 +1890,16 @@ OpenMPIRBuilder::createTask(const LocationDescription &Loc,
SplitBlockAndInsertIfThenElse(IfCondition, IfTerminator, &ThenTI,
&ElseTI);
Builder.SetInsertPoint(ElseTI);
+
+ if (Dependencies.size()) {
+ Function *TaskWaitFn =
+ getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_wait_deps);
+ Builder.CreateCall(
+ TaskWaitFn,
+ {Ident, ThreadID, Builder.getInt32(Dependencies.size()), DepArray,
+ ConstantInt::get(Builder.getInt32Ty(), 0),
+ ConstantPointerNull::get(PointerType::getUnqual(M.getContext()))});
+ }
Function *TaskBeginFn =
getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_begin_if0);
Function *TaskCompleteFn =
diff --git a/mlir/test/Target/LLVMIR/omptask_if_false.mlir b/mlir/test/Target/LLVMIR/omptask_if_false.mlir
new file mode 100644
index 0000000..c6014a7
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/omptask_if_false.mlir
@@ -0,0 +1,17 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+llvm.func @foo_(%arg0: !llvm.ptr {fir.bindc_name = "n"}, %arg1: !llvm.ptr {fir.bindc_name = "r"}) attributes {fir.internal_name = "_QPfoo"} {
+ %0 = llvm.mlir.constant(false) : i1
+ omp.task if(%0) depend(taskdependin -> %arg0 : !llvm.ptr) {
+ %1 = llvm.load %arg0 : !llvm.ptr -> i32
+ llvm.store %1, %arg1 : i32, !llvm.ptr
+ omp.terminator
+ }
+ llvm.return
+}
+
+// CHECK: call void @__kmpc_omp_wait_deps
+// CHECK-NEXT: call void @__kmpc_omp_task_begin_if0
+// CHECK-NEXT: call void @foo_..omp_par
+// CHECK-NEXT: call void @__kmpc_omp_task_complete_if0
+