[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
Wed Jun 24 05:15:43 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:

Please add a simple MLIR to LLVM IR translation test (one similar to mlir/test/Target/LLVMIR/openmp-target-in-reduction.mlir) for an offloading target. You'd just need to wrap it into something like this:
```mlir
module attributes {llvm.target_triple = "amdgcn-amd-amdhsa", omp.is_gpu = true, omp.is_target_device = true} {
  // ...
}
```
Mainly to check that the target region accesses the mapped variable normally and there are no `in_reduction`-related runtime calls.

https://github.com/llvm/llvm-project/pull/199967


More information about the flang-commits mailing list