[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:11 PDT 2026


================
@@ -369,10 +369,39 @@ static LogicalResult checkImplementationStatus(Operation &op) {
     if (op.getHint())
       op.emitWarning("hint clause discarded");
   };
+  // omp.target implements the non-byref in_reduction form for the
+  // host-fallback path. The byref form is not implemented yet, and declare
+  // reductions that use a cleanup region or a two-argument (alloc) initializer
+  // are also not implemented. (omp.task / omp.taskloop in_reduction are checked
+  // separately via checkInReductionByref.)
   auto checkInReduction = [&todo](auto op, LogicalResult &result) {
-    if (!op.getInReductionVars().empty() || op.getInReductionByref() ||
-        op.getInReductionSyms())
-      result = todo("in_reduction");
+    if (auto byrefAttr = op.getInReductionByref())
+      for (bool isByRef : *byrefAttr)
+        if (isByRef) {
+          result = todo("in_reduction with byref modifier");
+          return;
+        }
+    if (isa<omp::TargetOp>(op.getOperation())) {
+      if (auto inReductionSyms = op.getInReductionSyms()) {
+        for (auto sym :
+             (*inReductionSyms).template getAsRange<SymbolRefAttr>()) {
+          auto decl =
+              SymbolTable::lookupNearestSymbolFrom<omp::DeclareReductionOp>(
+                  op, sym);
+          // Symbol resolution is guaranteed by the op verifier.
+          if (!decl)
+            continue;
----------------
skatrak wrote:

```suggestion
          assert(decl && "symbol resolution should be guaranteed by the op verifier");
```

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


More information about the flang-commits mailing list