[Mlir-commits] [mlir] [mlir][OpenMP] Introduce 'omp.iterators' for OpenMP iterator modifiers (PR #182218)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Feb 19 10:59:12 PST 2026


chichunchen wrote:

> Can we get all of this information from the openmp loop nest? There is an omp.loop_nest op which should have all lower bounds, upper bounds and steps.

We can get the information about lowerbounds, upperbounds, steps, and induction variables from omp.loop_nest, however, I believe it is better to introduce a dedicated omp.iterators op for iterator modifiers for the following reasons.
1. iterator modifiers are clause metadata and not a loop construct in the program. Using omp.loop_nest would conceptually model this as executable loop control flow, which does not reflect the semantic role of iterator modifiers.
2. omp.iterators models "per-iteration entry generation"
    - In omp.iterator op, each iteration returns a `iterated<entry_type>` handle.
3. Here's some examples:
    - affinity clause: each iteration returns `!omp.iterated<omp.affinity_entry(addr, len)>`. 
       - omp.affinity_entry have enough info to build `kmp_task_affinity_info_t`.
    - depend clause: each iteration returns something like `!omp.iterated<kmp_depend_info>`
    - map/to/from: each iteration returns `!omp.iterated<!omp.map.info>`
```
  %it = omp.iterators(%iv: index) = (%lb to %ub step %step) {
    %e = omp.affinity_entry %addr, %len
      : (!llvm.ptr, i64) -> !omp.affinity_entry_ty<!llvm.ptr, i64>
    omp.yield(%e : !omp.affinity_entry_ty<!llvm.ptr, i64>)
  } -> !omp.iterated<!omp.affinity_entry_ty<!llvm.ptr, i64>>

  omp.task affinity(%it : !omp.iterated<!omp.affinity_entry_ty<!llvm.ptr, i64>>) {
    omp.terminator
  }
```
Conceptually, this lowers to:
```
 kmp_task_affinity_info_t affinity_info_list[tripcounts];
 for (int i = lb; i < ub; i += step) {
     affinity_info_list[i] = omp.iterators(i);
 }
```

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


More information about the Mlir-commits mailing list