[flang-commits] [flang] [llvm] [mlir] [flang][OpenMP] Lower target in_reduction for host fallback (PR #199967)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Mon Jul 13 05:20:21 PDT 2026
================
@@ -8605,6 +8702,42 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
targetOp.getPrivateNeedsBarrier(), &mappedPrivateVars)))
return llvm::make_error<PreviouslyReportedError>();
+ // The target body accesses each in_reduction variable through its
+ // map_entries block argument. Redirect that block argument to the per-task
+ // private storage returned by __kmpc_task_reduction_get_th_data so the body
+ // accumulates into the reduction-private copy rather than the mapped
+ // original. The lookup must run inside the target task body so the gtid
+ // corresponds to the executing thread. The descriptor argument is NULL: the
+ // runtime walks enclosing taskgroups to locate the matching task_reduction
+ // registration for `origPtr`. Mirrors the in_reduction handling on
+ // omp.taskloop.context.
+ if (!inRedOrigPtrs.empty()) {
+ // OpenMPIRBuilder owns the runtime-generation path: it computes the
+ // target body gtid once (so several in_reduction items do not each emit a
+ // __kmpc_global_thread_num) and emits the per-item
+ // __kmpc_task_reduction_get_th_data lookup with the required
+ // address-space casts. The MLIR-specific work stays here: collect, per
+ // item, the type the private pointer must have (the map block argument's
+ // type), and, through the callback, rebind the map block argument that
+ // stands in for each in_reduction list item to the per-task
+ // reduction-private storage the runtime returns.
----------------
skatrak wrote:
```suggestion
// Collect, per
// item, the type the private pointer must have (the map block argument's
// type), and, through the callback, rebind the map block argument that
// stands in for each in_reduction list item to the per-task
// reduction-private storage the runtime returns.
```
https://github.com/llvm/llvm-project/pull/199967
More information about the flang-commits
mailing list