Skip to content

[flang][OpenMP] Update do concurrent mapping pass to use fir.do_concurrent op #138489

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
May 8, 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
362 changes: 84 additions & 278 deletions flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions flang/test/Transforms/DoConcurrent/basic_device.mlir
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// RUN: fir-opt --omp-do-concurrent-conversion="map-to=device" -verify-diagnostics %s

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

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

return
Expand Down
3 changes: 0 additions & 3 deletions flang/test/Transforms/DoConcurrent/basic_host.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
! Fails until we update the pass to use the `fir.do_concurrent` op.
! XFAIL: *

! Tests mapping of a basic `do concurrent` loop to `!$omp parallel do`.

! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-to-openmp=host %s -o - \
Expand Down
26 changes: 14 additions & 12 deletions flang/test/Transforms/DoConcurrent/basic_host.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
func.func @do_concurrent_basic() attributes {fir.bindc_name = "do_concurrent_basic"} {
// 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>>)

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

// CHECK-NOT: fir.do_loop
// CHECK-NOT: fir.do_concurrent

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

// CHECK-NEXT: omp.terminator
// CHECK-NEXT: }
fir.do_loop %arg0 = %7 to %8 step %c1 unordered {
%13 = fir.convert %arg0 : (index) -> i32
fir.store %13 to %1#1 : !fir.ref<i32>
%14 = fir.load %1#0 : !fir.ref<i32>
%15 = fir.load %1#0 : !fir.ref<i32>
%16 = fir.convert %15 : (i32) -> i64
%17 = hlfir.designate %4#0 (%16) : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
hlfir.assign %14 to %17 : i32, !fir.ref<i32>
fir.do_concurrent {
%0 = fir.alloca i32 {bindc_name = "i"}
%1:2 = hlfir.declare %0 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
fir.do_concurrent.loop (%arg0) = (%7) to (%8) step (%c1) {
%13 = fir.convert %arg0 : (index) -> i32
fir.store %13 to %1#1 : !fir.ref<i32>
%14 = fir.load %1#0 : !fir.ref<i32>
%15 = fir.load %1#0 : !fir.ref<i32>
%16 = fir.convert %15 : (i32) -> i64
%17 = hlfir.designate %4#0 (%16) : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
hlfir.assign %14 to %17 : i32, !fir.ref<i32>
}
}

// CHECK-NOT: fir.do_loop
// CHECK-NOT: fir.do_concurrent

return
}
3 changes: 0 additions & 3 deletions flang/test/Transforms/DoConcurrent/locally_destroyed_temp.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
! Fails until we update the pass to use the `fir.do_concurrent` op.
! XFAIL: *

! Tests that "loop-local values" are properly handled by localizing them to the
! body of the loop nest. See `collectLoopLocalValues` and `localizeLoopLocalValue`
! for a definition of "loop-local values" and how they are handled.
Expand Down
92 changes: 0 additions & 92 deletions flang/test/Transforms/DoConcurrent/loop_nest_test.f90

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
! Fails until we update the pass to use the `fir.do_concurrent` op.
! XFAIL: *

! Tests mapping of a `do concurrent` loop with multiple iteration ranges.

! RUN: split-file %s %t
Expand Down
3 changes: 0 additions & 3 deletions flang/test/Transforms/DoConcurrent/non_const_bounds.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
! Fails until we update the pass to use the `fir.do_concurrent` op.
! XFAIL: *

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

Expand Down
24 changes: 11 additions & 13 deletions flang/test/Transforms/DoConcurrent/not_perfectly_nested.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
! Fails until we update the pass to use the `fir.do_concurrent` op.
! XFAIL: *

! Tests that if `do concurrent` is not perfectly nested in its parent loop, that
! we skip converting the not-perfectly nested `do concurrent` loop.

Expand All @@ -22,23 +19,24 @@ program main
end do
end

! CHECK: %[[ORIG_K_ALLOC:.*]] = fir.alloca i32 {bindc_name = "k"}
! CHECK: %[[ORIG_K_DECL:.*]]:2 = hlfir.declare %[[ORIG_K_ALLOC]]

! CHECK: %[[ORIG_J_ALLOC:.*]] = fir.alloca i32 {bindc_name = "j"}
! CHECK: %[[ORIG_J_DECL:.*]]:2 = hlfir.declare %[[ORIG_J_ALLOC]]

! CHECK: omp.parallel {

! CHECK: omp.wsloop {
! CHECK: omp.loop_nest ({{[^[:space:]]+}}) {{.*}} {
! CHECK: fir.do_loop %[[J_IV:.*]] = {{.*}} {
! CHECK: %[[J_IV_CONV:.*]] = fir.convert %[[J_IV]] : (index) -> i32
! CHECK: fir.do_concurrent {

! CHECK: %[[ORIG_J_ALLOC:.*]] = fir.alloca i32 {bindc_name = "j"}
! CHECK: %[[ORIG_J_DECL:.*]]:2 = hlfir.declare %[[ORIG_J_ALLOC]]

! CHECK: %[[ORIG_K_ALLOC:.*]] = fir.alloca i32 {bindc_name = "k"}
! CHECK: %[[ORIG_K_DECL:.*]]:2 = hlfir.declare %[[ORIG_K_ALLOC]]

! CHECK: fir.do_concurrent.loop (%[[J_IV:.*]], %[[K_IV:.*]]) = {{.*}} {
! CHECK: %[[J_IV_CONV:.*]] = fir.convert %[[J_IV]] : (index) -> i32
! CHECK: fir.store %[[J_IV_CONV]] to %[[ORIG_J_DECL]]#0

! CHECK: fir.do_loop %[[K_IV:.*]] = {{.*}} {
! CHECK: %[[K_IV_CONV:.*]] = fir.convert %[[K_IV]] : (index) -> i32
! CHECK: fir.store %[[K_IV_CONV]] to %[[ORIG_K_DECL]]#0
! CHECK: fir.store %[[K_IV_CONV]] to %[[ORIG_K_DECL]]#0
! CHECK: }
! CHECK: }
! CHECK: omp.yield
Expand Down