Skip to content

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

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

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
20 changes: 19 additions & 1 deletion flang/test/Lower/OpenMP/generic-loop-rewriting.f90
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:]]+]],
Expand Down
16 changes: 0 additions & 16 deletions flang/test/Transforms/generic-loop-rewriting-todo.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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@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
Expand Down