[flang-commits] [flang] [mlir] [flang][OpenMP] Lower target in_reduction for host fallback (PR #199967)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Tue Jun 23 06:55:14 PDT 2026
================
@@ -8363,6 +8396,59 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
bool isOffloadEntry =
isTargetDevice || !ompBuilder->Config.TargetTriples.empty();
+ // Validate and resolve in_reduction clauses on omp.target. We currently
+ // only support the non-offload host-fallback path: the per-task private
+ // pointer is obtained by calling __kmpc_task_reduction_get_th_data inside
+ // the to-be-outlined target task body. Threading that pointer through the
+ // device kernel argument list is left as follow-up work.
+ SmallVector<llvm::Value *> inRedOrigPtrs;
+ SmallVector<unsigned> inRedMapArgIdx;
+ if (!targetOp.getInReductionVars().empty()) {
+ if (isTargetDevice || isOffloadEntry)
+ return opInst.emitError(
+ "not yet implemented: in_reduction clause on omp.target with "
+ "offload / target-device compilation");
----------------
skatrak wrote:
Wouldn't this work already for both offloading and non-offloading modules? It seems that, as long as the `if (llvm::is_contained(inRedMapArgIdx, idx))` and `if (!inRedOrigPtrs.empty())` statements below also make sure that `!isTargetDevice`, then it should work. Do let me know if there are problems with this suggestion, though.
```suggestion
if (!targetOp.getInReductionVars().empty() && !isTargetDevice) {
```
https://github.com/llvm/llvm-project/pull/199967
More information about the flang-commits
mailing list