Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][OpenMP] Support bind clause for teams loop #127021

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

ergawy
Copy link
Member

@ergawy ergawy commented Feb 13, 2025

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.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp labels Feb 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 13, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-fir-hlfir

Author: Kareem Ergawy (ergawy)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/127021.diff

2 Files Affected:

  • (modified) flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp (+4-3)
  • (modified) flang/test/Lower/OpenMP/generic-loop-rewriting.f90 (+19-1)
diff --git a/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp b/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
index 3512a537d38c3..0559194c2ed62 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 standalone 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:]]+]],

@ergawy ergawy force-pushed the target_teams_loop_bind_clause branch from b5b8e68 to b353b0b Compare February 13, 2025 08:00
@ergawy ergawy requested review from skatrak and mjklemm February 13, 2025 08:01
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.
@ergawy ergawy force-pushed the target_teams_loop_bind_clause branch from b353b0b to 314d858 Compare February 13, 2025 08:24
Copy link
Member

@skatrak skatrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ergawy ergawy merged commit 919e72f into llvm:main Feb 17, 2025
8 checks passed
YutongZhuu pushed a commit to YutongZhuu/llvm-project that referenced this pull request Mar 8, 2025
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.
YutongZhuu pushed a commit to YutongZhuu/llvm-project that referenced this pull request Mar 8, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants