[flang-commits] [flang] [llvm] [mlir] [flang][OpenMP] Lower target in_reduction (PR #199967)

Sairudra More via flang-commits flang-commits at lists.llvm.org
Mon Jul 13 07:48:55 PDT 2026


================
@@ -2440,6 +2440,39 @@ class OpenMPIRBuilder {
 
   ///}
 
+  /// Emit the host-fallback runtime lookups that redirect the `in_reduction`
+  /// list items of an `omp.target` region to their per-task reduction-private
+  /// storage.
+  ///
+  /// This owns the complete runtime-generation path for target `in_reduction`.
+  /// It computes the executing thread's gtid once for the whole target body (so
+  /// a target with several in_reduction items does not emit a redundant
+  /// `__kmpc_global_thread_num` per item), then for each item emits
+  /// `__kmpc_task_reduction_get_th_data(gtid, /*descriptor=*/null, origPtr)`
+  /// with the address-space normalization required by the runtime entry point.
+  /// The NULL descriptor makes the runtime walk the enclosing taskgroups to
+  /// find the matching `task_reduction` registration for the item. The lookups
+  /// are emitted at \p Loc, which must be inside the target task body.
+  ///
+  /// The front-end-specific work (matching each `in_reduction` item to its
+  /// mapped storage and binding the generated private pointer back to the
+  /// right value) stays with the caller: each generated private pointer is
+  /// handed back through \p MapPrivate.
+  ///
+  /// \param Loc          Insertion point for the target body.
+  /// \param OrigPtrs     Per item, the mapped original pointer used as the
+  ///                     runtime `orig` argument.
+  /// \param ResultPtrTys Per item, the type the returned private pointer must
+  ///                     have (for address-space normalization). Must have the
+  ///                     same length as \p OrigPtrs.
+  /// \param MapPrivate   Called once per item, in list order, with the item
+  ///                     index and the generated per-task private pointer.
+  /// \returns The insertion point after the emitted lookups.
+  LLVM_ABI InsertPointTy createTargetInReduction(
+      const LocationDescription &Loc, ArrayRef<Value *> OrigPtrs,
+      ArrayRef<Type *> ResultPtrTys,
+      function_ref<void(unsigned, Value *)> MapPrivate);
----------------
Saieiei wrote:

Done!


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


More information about the flang-commits mailing list