Skip to content

Commit 919e72f

Browse files
authored
[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.
1 parent 4e41e9a commit 919e72f

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ class GenericLoopConversionPattern
8484
<< loopOp->getName() << " operation";
8585
};
8686

87-
// For standalone directives, `bind` is already supported. Other combined
88-
// forms will be supported in a follow-up PR.
89-
if (combinedInfo != GenericLoopCombinedInfo::Standalone &&
87+
// For `loop` and `teams loop` directives, `bind` is supported.
88+
// Additionally, for `teams loop`, semantic checking verifies that the
89+
// `bind` clause modifier is `teams`, so no need to check this here again.
90+
if (combinedInfo == GenericLoopCombinedInfo::ParallelLoop &&
9091
loopOp.getBindKind())
9192
return todo("bind");
9293

flang/test/Lower/OpenMP/generic-loop-rewriting.f90

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
1+
!RUN: split-file %s %t
22

3+
!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %t/no_bind_clause.f90 -o - \
4+
!RUN: | FileCheck %s
5+
6+
!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %t/bind_clause_teams.f90 -o - \
7+
!RUN: | FileCheck %s
8+
9+
!--- no_bind_clause.f90
310
subroutine target_teams_loop
411
implicit none
512
integer :: x, i
@@ -10,6 +17,17 @@ subroutine target_teams_loop
1017
end do
1118
end subroutine target_teams_loop
1219

20+
!--- bind_clause_teams.f90
21+
subroutine target_teams_loop
22+
implicit none
23+
integer :: x, i
24+
25+
!$omp target teams loop bind(teams)
26+
do i = 0, 10
27+
x = x + i
28+
end do
29+
end subroutine target_teams_loop
30+
1331
!CHECK-LABEL: func.func @_QPtarget_teams_loop
1432
!CHECK: omp.target map_entries(
1533
!CHECK-SAME: %{{.*}} -> %[[I_ARG:[^[:space:]]+]],

flang/test/Transforms/generic-loop-rewriting-todo.mlir

-16
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,6 @@ func.func @_QPparallel_loop() {
1616
return
1717
}
1818

19-
func.func @_QPloop_bind() {
20-
omp.teams {
21-
%c0 = arith.constant 0 : i32
22-
%c10 = arith.constant 10 : i32
23-
%c1 = arith.constant 1 : i32
24-
// expected-error@below {{not yet implemented: Unhandled clause bind in omp.loop operation}}
25-
omp.loop bind(thread) {
26-
omp.loop_nest (%arg3) : i32 = (%c0) to (%c10) inclusive step (%c1) {
27-
omp.yield
28-
}
29-
}
30-
omp.terminator
31-
}
32-
return
33-
}
34-
3519
omp.declare_reduction @add_reduction_i32 : i32 init {
3620
^bb0(%arg0: i32):
3721
%c0_i32 = arith.constant 0 : i32

0 commit comments

Comments
 (0)