<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/126949>126949</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[OMPIRBuilder] - Empty target task proxy function generated by OMPIRBuilder (`emitTargetTaskProxyFunction`)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
openmp,
mlir,
llvm:openmpirbuilder
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bhandarkar-pranav
</td>
</tr>
</table>
<pre>
Reproducer:
```
$> mlir-translate -mlir-to-llvmir ${LLVM_PROJECT_DIR}/mlir/test/Target/LLVMIR/omptarget-depend-host-only
$> cat ${LLVM_PROJECT_DIR}/mlir/test/Target/LLVMIR/omptarget-depend-host-only.mlir
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
module attributes {omp.is_target_device = false} {
llvm.func @omp_target_depend_() {
%0 = llvm.mlir.constant(39 : index) : i64
%1 = llvm.mlir.constant(1 : index) : i64
%2 = llvm.mlir.constant(40 : index) : i64
%3 = omp.map.bounds lower_bound(%1 : i64) upper_bound(%0 : i64) extent(%2 : i64) stride(%1 : i64) start_idx(%1 : i64)
%4 = llvm.mlir.addressof @_QFEa : !llvm.ptr
%5 = omp.map.info var_ptr(%4 : !llvm.ptr, !llvm.array<40 x i32>) map_clauses(from) capture(ByRef) bounds(%3) -> !llvm.ptr {name = "a"}
omp.target depend(taskdependin -> %4 : !llvm.ptr) map_entries(%5 -> %arg0 : !llvm.ptr) {
%6 = llvm.mlir.constant(100 : index) : i32
llvm.store %6, %arg0 : i32, !llvm.ptr
omp.terminator
}
llvm.return
}
llvm.mlir.global internal @_QFEa() {addr_space = 0 : i32} : !llvm.array<40 x i32> {
%0 = llvm.mlir.zero : !llvm.array<40 x i32>
llvm.return %0 : !llvm.array<40 x i32>
}
}
// CHECK: define void @omp_target_depend_()
// CHECK-NOT: define {{.*}} @
// CHECK-NOT: call i32 @__tgt_target_kernel({{.*}})
// CHECK: call void @__omp_offloading_[[DEV:.*]]_[[FIL:.*]]_omp_target_depend__l[[LINE:.*]](ptr {{.*}})
// CHECK-NEXT: ret void
// CHECK: define internal void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_depend__l[[LINE]](ptr %[[ADDR_A:.*]])
// CHECK: store i32 100, ptr %[[ADDR_A]], align 4
```
Two problems in the output
1. Empty target task proxy function `@.omp_target_task_proxy_func`
```
define internal void @.omp_target_task_proxy_func(i32 %thread.id, ptr %task) {
entry:
ret void
}
```
2. After 1 is fixed, we'll end up with dual execution of the kernel because we hit a corner case (single basic block task bodies) in `OpenMPIRBuilder::OutlineInfo::collectBlocks` such that the entire task body is not outlined in the target task.
```
codeRepl: ; preds = %entry
%omp_global_thread_num = call i32 @__kmpc_global_thread_num(ptr @2)
%5 = call ptr @__kmpc_omp_task_alloc(ptr @2, i32 %omp_global_thread_num, i32 0, i64 40, i64 0, ptr @.omp_target_task_proxy_func)
call void @__kmpc_omp_wait_deps(ptr @2, i32 %omp_global_thread_num, i32 1, ptr %.dep.arr.addr, i32 0, ptr null)
call void @__kmpc_omp_task_begin_if0(ptr @2, i32 %omp_global_thread_num, ptr %5)
call void @.omp_target_task_proxy_func(i32 %omp_global_thread_num, ptr %5) ;;; first execution of the kernel once problem 1 is fixed.
call void @__kmpc_omp_task_complete_if0(ptr @2, i32 %omp_global_thread_num, ptr %5)
br label %target.task.body
target.task.body: ; preds = %codeRepl
call void @__omp_offloading_10307_a581555_omp_target_depend__l11(ptr @_QFEa) ;;;; Second execution of the kernel when problem 1 is fixed
ret void
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V01v67oR_TX0hrAhUZI_Fl74E017382rmz50J1DSyGZDkQJJJXF_fTGUbMuOE9-2KGAgETln5szhzFDi1oq9ApiTZEmS9YA37qDNPDtwVXDzys2wNlzxt0Gmi-N8B7XRRZODIdGCkmCBv3HQ_YIFYTGJNrSSwgyd4cpK7o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