Skip to content

Commit 96b00e2

Browse files
committed
[flang][OpenMP] Update do concurrent mapping pass to use fir.do_concurrent op
This PR updates the `do concurrent` to OpenMP mapping pass to use the newly added `fir.do_concurrent` ops that were recently added upstream instead of handling nests of `fir.do_loop ... unordered` ops. Parent PR: #137928.
1 parent fc8484f commit 96b00e2

9 files changed

+122
-418
lines changed

flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp

Lines changed: 84 additions & 278 deletions
Large diffs are not rendered by default.

flang/test/Transforms/DoConcurrent/basic_device.mlir

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// RUN: fir-opt --omp-do-concurrent-conversion="map-to=device" -verify-diagnostics %s
22

33
func.func @do_concurrent_basic() attributes {fir.bindc_name = "do_concurrent_basic"} {
4-
%0 = fir.alloca i32 {bindc_name = "i"}
5-
%1:2 = hlfir.declare %0 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
64
%2 = fir.address_of(@_QFEa) : !fir.ref<!fir.array<10xi32>>
75
%c10 = arith.constant 10 : index
86
%3 = fir.shape %c10 : (index) -> !fir.shape<1>
@@ -14,15 +12,19 @@ func.func @do_concurrent_basic() attributes {fir.bindc_name = "do_concurrent_bas
1412
%c1 = arith.constant 1 : index
1513

1614
// expected-error@+2 {{not yet implemented: Mapping `do concurrent` loops to device}}
17-
// expected-error@below {{failed to legalize operation 'fir.do_loop'}}
18-
fir.do_loop %arg0 = %7 to %8 step %c1 unordered {
19-
%13 = fir.convert %arg0 : (index) -> i32
20-
fir.store %13 to %1#1 : !fir.ref<i32>
21-
%14 = fir.load %1#0 : !fir.ref<i32>
22-
%15 = fir.load %1#0 : !fir.ref<i32>
23-
%16 = fir.convert %15 : (i32) -> i64
24-
%17 = hlfir.designate %4#0 (%16) : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
25-
hlfir.assign %14 to %17 : i32, !fir.ref<i32>
15+
// expected-error@below {{failed to legalize operation 'fir.do_concurrent'}}
16+
fir.do_concurrent {
17+
%0 = fir.alloca i32 {bindc_name = "i"}
18+
%1:2 = hlfir.declare %0 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
19+
fir.do_concurrent.loop (%arg0) = (%7) to (%8) step (%c1) {
20+
%13 = fir.convert %arg0 : (index) -> i32
21+
fir.store %13 to %1#1 : !fir.ref<i32>
22+
%14 = fir.load %1#0 : !fir.ref<i32>
23+
%15 = fir.load %1#0 : !fir.ref<i32>
24+
%16 = fir.convert %15 : (i32) -> i64
25+
%17 = hlfir.designate %4#0 (%16) : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
26+
hlfir.assign %14 to %17 : i32, !fir.ref<i32>
27+
}
2628
}
2729

2830
return

flang/test/Transforms/DoConcurrent/basic_host.f90

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
! Fails until we update the pass to use the `fir.do_concurrent` op.
2-
! XFAIL: *
3-
41
! Tests mapping of a basic `do concurrent` loop to `!$omp parallel do`.
52

63
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-to-openmp=host %s -o - \

flang/test/Transforms/DoConcurrent/basic_host.mlir

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
func.func @do_concurrent_basic() attributes {fir.bindc_name = "do_concurrent_basic"} {
77
// CHECK: %[[ARR:.*]]:2 = hlfir.declare %{{.*}}(%{{.*}}) {uniq_name = "_QFEa"} : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10xi32>>, !fir.ref<!fir.array<10xi32>>)
88

9-
%0 = fir.alloca i32 {bindc_name = "i"}
10-
%1:2 = hlfir.declare %0 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
119
%2 = fir.address_of(@_QFEa) : !fir.ref<!fir.array<10xi32>>
1210
%c10 = arith.constant 10 : index
1311
%3 = fir.shape %c10 : (index) -> !fir.shape<1>
@@ -18,7 +16,7 @@ func.func @do_concurrent_basic() attributes {fir.bindc_name = "do_concurrent_bas
1816
%8 = fir.convert %c10_i32 : (i32) -> index
1917
%c1 = arith.constant 1 : index
2018

21-
// CHECK-NOT: fir.do_loop
19+
// CHECK-NOT: fir.do_concurrent
2220

2321
// CHECK: %[[C1:.*]] = arith.constant 1 : i32
2422
// CHECK: %[[LB:.*]] = fir.convert %[[C1]] : (i32) -> index
@@ -46,17 +44,21 @@ func.func @do_concurrent_basic() attributes {fir.bindc_name = "do_concurrent_bas
4644

4745
// CHECK-NEXT: omp.terminator
4846
// CHECK-NEXT: }
49-
fir.do_loop %arg0 = %7 to %8 step %c1 unordered {
50-
%13 = fir.convert %arg0 : (index) -> i32
51-
fir.store %13 to %1#1 : !fir.ref<i32>
52-
%14 = fir.load %1#0 : !fir.ref<i32>
53-
%15 = fir.load %1#0 : !fir.ref<i32>
54-
%16 = fir.convert %15 : (i32) -> i64
55-
%17 = hlfir.designate %4#0 (%16) : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
56-
hlfir.assign %14 to %17 : i32, !fir.ref<i32>
47+
fir.do_concurrent {
48+
%0 = fir.alloca i32 {bindc_name = "i"}
49+
%1:2 = hlfir.declare %0 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
50+
fir.do_concurrent.loop (%arg0) = (%7) to (%8) step (%c1) {
51+
%13 = fir.convert %arg0 : (index) -> i32
52+
fir.store %13 to %1#1 : !fir.ref<i32>
53+
%14 = fir.load %1#0 : !fir.ref<i32>
54+
%15 = fir.load %1#0 : !fir.ref<i32>
55+
%16 = fir.convert %15 : (i32) -> i64
56+
%17 = hlfir.designate %4#0 (%16) : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
57+
hlfir.assign %14 to %17 : i32, !fir.ref<i32>
58+
}
5759
}
5860

59-
// CHECK-NOT: fir.do_loop
61+
// CHECK-NOT: fir.do_concurrent
6062

6163
return
6264
}

flang/test/Transforms/DoConcurrent/locally_destroyed_temp.f90

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
! Fails until we update the pass to use the `fir.do_concurrent` op.
2-
! XFAIL: *
3-
41
! Tests that "loop-local values" are properly handled by localizing them to the
52
! body of the loop nest. See `collectLoopLocalValues` and `localizeLoopLocalValue`
63
! for a definition of "loop-local values" and how they are handled.

flang/test/Transforms/DoConcurrent/loop_nest_test.f90

Lines changed: 0 additions & 92 deletions
This file was deleted.

flang/test/Transforms/DoConcurrent/multiple_iteration_ranges.f90

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
! Fails until we update the pass to use the `fir.do_concurrent` op.
2-
! XFAIL: *
3-
41
! Tests mapping of a `do concurrent` loop with multiple iteration ranges.
52

63
! RUN: split-file %s %t

flang/test/Transforms/DoConcurrent/non_const_bounds.f90

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
! Fails until we update the pass to use the `fir.do_concurrent` op.
2-
! XFAIL: *
3-
41
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-to-openmp=host %s -o - \
52
! RUN: | FileCheck %s
63

flang/test/Transforms/DoConcurrent/not_perfectly_nested.f90

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
! Fails until we update the pass to use the `fir.do_concurrent` op.
2-
! XFAIL: *
3-
41
! Tests that if `do concurrent` is not perfectly nested in its parent loop, that
52
! we skip converting the not-perfectly nested `do concurrent` loop.
63

@@ -22,23 +19,24 @@ program main
2219
end do
2320
end
2421

25-
! CHECK: %[[ORIG_K_ALLOC:.*]] = fir.alloca i32 {bindc_name = "k"}
26-
! CHECK: %[[ORIG_K_DECL:.*]]:2 = hlfir.declare %[[ORIG_K_ALLOC]]
27-
28-
! CHECK: %[[ORIG_J_ALLOC:.*]] = fir.alloca i32 {bindc_name = "j"}
29-
! CHECK: %[[ORIG_J_DECL:.*]]:2 = hlfir.declare %[[ORIG_J_ALLOC]]
30-
3122
! CHECK: omp.parallel {
3223

3324
! CHECK: omp.wsloop {
3425
! CHECK: omp.loop_nest ({{[^[:space:]]+}}) {{.*}} {
35-
! CHECK: fir.do_loop %[[J_IV:.*]] = {{.*}} {
36-
! CHECK: %[[J_IV_CONV:.*]] = fir.convert %[[J_IV]] : (index) -> i32
26+
! CHECK: fir.do_concurrent {
27+
28+
! CHECK: %[[ORIG_J_ALLOC:.*]] = fir.alloca i32 {bindc_name = "j"}
29+
! CHECK: %[[ORIG_J_DECL:.*]]:2 = hlfir.declare %[[ORIG_J_ALLOC]]
30+
31+
! CHECK: %[[ORIG_K_ALLOC:.*]] = fir.alloca i32 {bindc_name = "k"}
32+
! CHECK: %[[ORIG_K_DECL:.*]]:2 = hlfir.declare %[[ORIG_K_ALLOC]]
33+
34+
! CHECK: fir.do_concurrent.loop (%[[J_IV:.*]], %[[K_IV:.*]]) = {{.*}} {
35+
! CHECK: %[[J_IV_CONV:.*]] = fir.convert %[[J_IV]] : (index) -> i32
3736
! CHECK: fir.store %[[J_IV_CONV]] to %[[ORIG_J_DECL]]#0
3837

39-
! CHECK: fir.do_loop %[[K_IV:.*]] = {{.*}} {
4038
! CHECK: %[[K_IV_CONV:.*]] = fir.convert %[[K_IV]] : (index) -> i32
41-
! CHECK: fir.store %[[K_IV_CONV]] to %[[ORIG_K_DECL]]#0
39+
! CHECK: fir.store %[[K_IV_CONV]] to %[[ORIG_K_DECL]]#0
4240
! CHECK: }
4341
! CHECK: }
4442
! CHECK: omp.yield

0 commit comments

Comments
 (0)