[Mlir-commits] [flang] [llvm] [mlir] [flang][OpenMP] Enable tiling (PR #143715)

Sergio Afonso llvmlistbot at llvm.org
Thu Aug 28 07:14:17 PDT 2025


================
@@ -271,12 +271,25 @@ bool ClauseProcessor::processCancelDirectiveName(
   return true;
 }
 
-bool ClauseProcessor::processCollapse(
+bool ClauseProcessor::processLoopNests(
     mlir::Location currentLocation, lower::pft::Evaluation &eval,
     mlir::omp::LoopRelatedClauseOps &result,
     llvm::SmallVectorImpl<const semantics::Symbol *> &iv) const {
-  return collectLoopRelatedInfo(converter, currentLocation, eval, clauses,
-                                result, iv);
+  int64_t numCollapse = collectLoopRelatedInfo(converter, currentLocation, eval,
+                                               clauses, result, iv);
+  return numCollapse > 1;
+}
----------------
skatrak wrote:

I think we shouldn't introduce this function and instead replace uses with `processCollapse`. By calling this instead of `processCollapse` in `processHostEvalClauses`, the result is that we discard collapse information on the host, so host fallback will behave as if the clause wasn't there. For example:
```f90
subroutine test()
  implicit none
  integer :: i, j

  !$omp target teams distribute parallel do collapse(2)
  do i=1,10
    do j=1,20
      call foo(i, j)
    end do
  end do
end subroutine
```
Will result in the following MLIR for the `omp.loop_nest` for host and device:
```mlir
// Host
// flang -fc1 -emit-hlfir -fopenmp test.f90 -o - | grep omp.loop_nest
omp.loop_nest (%arg10, %arg11) : i32 = (%arg0, %arg1) to (%arg2, %arg3) inclusive step (%arg4, %arg5) { ... }

// Device
// flang -fc1 -emit-hlfir -fopenmp -fopenmp-is-target-device test.f90 -o - | grep omp.loop_nest
omp.loop_nest (%arg4, %arg5) : i32 = (%c1_i32, %c1_i32_1) to (%c10_i32, %c20_i32) inclusive step (%c1_i32_0, %c1_i32_2) collapse(2) { ... }
```

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


More information about the Mlir-commits mailing list