[flang-commits] [flang] 919e72f - [flang][OpenMP] Support `bind` clause for `teams loop` (#127021)

via flang-commits flang-commits at lists.llvm.org
Mon Feb 17 06:18:30 PST 2025


Author: Kareem Ergawy
Date: 2025-02-17T15:18:27+01:00
New Revision: 919e72f2513d57fc2105f6e3477c13eb1f0c6cba

URL: https://github.com/llvm/llvm-project/commit/919e72f2513d57fc2105f6e3477c13eb1f0c6cba
DIFF: https://github.com/llvm/llvm-project/commit/919e72f2513d57fc2105f6e3477c13eb1f0c6cba.diff

LOG: [flang][OpenMP] Support `bind` clause for `teams loop` (#127021)

Extends generic `loop` directive support by supporting the `bind`
clause. Since semantic checking does the heavy lifting of verifying the
proper usage of the clause modifier, we can simply enable code-gen for
`teams loop bind(...)` without the need to differentiate between the
values the the clause can accept.

Added: 
    

Modified: 
    flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
    flang/test/Lower/OpenMP/generic-loop-rewriting.f90
    flang/test/Transforms/generic-loop-rewriting-todo.mlir

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
index 3512a537d38c3..d2581e3ad0a0a 100644
--- a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
+++ b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
@@ -84,9 +84,10 @@ class GenericLoopConversionPattern
              << loopOp->getName() << " operation";
     };
 
-    // For standalone directives, `bind` is already supported. Other combined
-    // forms will be supported in a follow-up PR.
-    if (combinedInfo != GenericLoopCombinedInfo::Standalone &&
+    // For `loop` and `teams loop` directives, `bind` is supported.
+    // Additionally, for `teams loop`, semantic checking verifies that the
+    // `bind` clause modifier is `teams`, so no need to check this here again.
+    if (combinedInfo == GenericLoopCombinedInfo::ParallelLoop &&
         loopOp.getBindKind())
       return todo("bind");
 

diff  --git a/flang/test/Lower/OpenMP/generic-loop-rewriting.f90 b/flang/test/Lower/OpenMP/generic-loop-rewriting.f90
index fa26425356dd9..0699c36c69519 100644
--- a/flang/test/Lower/OpenMP/generic-loop-rewriting.f90
+++ b/flang/test/Lower/OpenMP/generic-loop-rewriting.f90
@@ -1,5 +1,12 @@
-!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+!RUN: split-file %s %t
 
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %t/no_bind_clause.f90 -o - \
+!RUN: | FileCheck %s
+
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %t/bind_clause_teams.f90 -o - \
+!RUN: | FileCheck %s
+
+!--- no_bind_clause.f90
 subroutine target_teams_loop
     implicit none
     integer :: x, i
@@ -10,6 +17,17 @@ subroutine target_teams_loop
     end do
 end subroutine target_teams_loop
 
+!--- bind_clause_teams.f90
+subroutine target_teams_loop
+    implicit none
+    integer :: x, i
+
+    !$omp target teams loop bind(teams)
+    do i = 0, 10
+      x = x + i
+    end do
+end subroutine target_teams_loop
+
 !CHECK-LABEL: func.func @_QPtarget_teams_loop
 !CHECK:         omp.target map_entries(
 !CHECK-SAME:      %{{.*}} -> %[[I_ARG:[^[:space:]]+]],

diff  --git a/flang/test/Transforms/generic-loop-rewriting-todo.mlir b/flang/test/Transforms/generic-loop-rewriting-todo.mlir
index cbde981c4c49d..25baffe34e394 100644
--- a/flang/test/Transforms/generic-loop-rewriting-todo.mlir
+++ b/flang/test/Transforms/generic-loop-rewriting-todo.mlir
@@ -16,22 +16,6 @@ func.func @_QPparallel_loop() {
   return
 }
 
-func.func @_QPloop_bind() {
-  omp.teams {
-    %c0 = arith.constant 0 : i32
-    %c10 = arith.constant 10 : i32
-    %c1 = arith.constant 1 : i32
-    // expected-error at below {{not yet implemented: Unhandled clause bind in omp.loop operation}}
-    omp.loop bind(thread) {
-      omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
-        omp.yield
-      }
-    }
-    omp.terminator
-  }
-  return
-}
-
 omp.declare_reduction @add_reduction_i32 : i32 init {
   ^bb0(%arg0: i32):
     %c0_i32 = arith.constant 0 : i32


        


More information about the flang-commits mailing list