[flang-commits] [flang] [mlir] [mlir][OpenMP] Add iterator support to map/motion clause (PR #197047)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Fri Jun 5 06:12:00 PDT 2026


================
@@ -311,6 +311,7 @@ class FunctionFilteringPass
       targetOp.setDependKindsAttr(nullptr);
       targetOp.getDependIteratedMutable().clear();
       targetOp.setDependIteratedKindsAttr(nullptr);
+      targetOp.getMapIteratedMutable().clear();
----------------
skatrak wrote:

I think it's a good idea to split `target map(...)` iterator support from the rest of operations into separate patches, since it has to address some extra challenges.

I do have a question about your proposal for `target map(...)`, though. Why do you need in this case to redundantly add references to `%a` and `%b`? In the other iterator cases, users only need the `omp.iterator`-defined value, which in its region holds references to the equivalent of `%a` or `%b`. The difference in the `target` case would be the need for an entry block argument, so it seems like this would be enough (and it would prevent the potential for a contradicting use vs. definition of the iterator):

```mlir
%it.a = omp.iterator(%i: index) = (%lb to %ub step %step) {
  %elem.a = ... %a[%i] ...
  %map.a = omp.map.info var_ptr(%elem.a : !llvm.ptr, i32)
           map_clauses(tofrom) capture(ByRef) -> !llvm.ptr
  omp.yield(%map.a : !llvm.ptr)
} -> !omp.iterated<!llvm.ptr>

%it.b = omp.iterator(%j: index) = (%lb to %ub step %step) {
  %elem.b = ... %b[%j] ...
  %map.b = omp.map.info var_ptr(%elem.b : !llvm.ptr, i32)
           map_clauses(to) capture(ByRef) -> !llvm.ptr
  omp.yield(%map.b : !llvm.ptr)
} -> !omp.iterated<!llvm.ptr>

omp.target map_iterated(
  %it.a -> %a.dev, %it.b -> %b.dev :
  !omp.iterated<!llvm.ptr>, !omp.iterated<!llvm.ptr>) {
  // Use %a.dev : !llvm.ptr and %b.dev : !llvm.ptr...
  omp.terminator
}
```

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


More information about the flang-commits mailing list