|
| 1 | +! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s --check-prefixes=CHECK,FIR |
| 2 | +! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s --check-prefixes=CHECK,HLFIR |
| 3 | + |
| 4 | +subroutine atomic_update_array1(r, n, x) |
| 5 | + implicit none |
| 6 | + integer :: n |
| 7 | + real :: r(n), x |
| 8 | + integer :: i |
| 9 | + |
| 10 | + !$acc data copy(r) |
| 11 | + |
| 12 | + !$acc parallel loop |
| 13 | + do i = 1, n |
| 14 | + !$acc atomic update |
| 15 | + r(i) = r(i) + x |
| 16 | + !$acc end atomic |
| 17 | + end do |
| 18 | + |
| 19 | + !$acc end data |
| 20 | +end subroutine |
| 21 | + |
| 22 | +! CHECK-LABEL: func.func @_QPatomic_update_array1( |
| 23 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "r"}, %[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}, %[[ARG2:.*]]: !fir.ref<f32> {fir.bindc_name = "x"}) { |
| 24 | +! HLFIR: %[[DECL_ARG2:.*]]:2 = hlfir.declare %[[ARG2]] {uniq_name = "_QFatomic_update_array1Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 25 | +! HLFIR: %[[DECL_ARG0:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) {uniq_name = "_QFatomic_update_array1Er"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>) |
| 26 | +! FIR: %[[ARRAY_REF:.*]] = fir.coordinate_of %[[ARG0]], %{{.*}} : (!fir.ref<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 27 | +! HLFIR: %[[ARRAY_REF:.*]] = hlfir.designate %[[DECL_ARG0]]#0 (%{{.*}}) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 28 | +! FIR: %[[LOAD_X:.*]] = fir.load %[[ARG2]] : !fir.ref<f32> |
| 29 | +! HLFIR: %[[LOAD_X:.*]] = fir.load %[[DECL_ARG2]]#0 : !fir.ref<f32> |
| 30 | +! CHECK: acc.atomic.update %[[ARRAY_REF]] : !fir.ref<f32> { |
| 31 | +! CHECK: ^bb0(%[[ARG:.*]]: f32): |
| 32 | +! CHECK: %[[ATOMIC:.*]] = arith.addf %[[ARG]], %[[LOAD_X]] fastmath<contract> : f32 |
| 33 | +! CHECK: acc.yield %[[ATOMIC]] : f32 |
| 34 | +! CHECK: } |
| 35 | + |
| 36 | + |
| 37 | +subroutine atomic_read_array1(r, n, x) |
| 38 | + implicit none |
| 39 | + integer :: n |
| 40 | + real :: r(n), x |
| 41 | + |
| 42 | + !$acc atomic read |
| 43 | + x = r(n) |
| 44 | +end subroutine |
| 45 | + |
| 46 | +! CHECK-LABEL: func.func @_QPatomic_read_array1( |
| 47 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "r"}, %[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}, %[[ARG2:.*]]: !fir.ref<f32> {fir.bindc_name = "x"}) { |
| 48 | +! FIR: %[[ARRAY_REF:.*]] = fir.coordinate_of %[[ARG0]], %{{.*}} : (!fir.ref<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 49 | +! FIR: acc.atomic.read %[[ARG2]] = %[[ARRAY_REF]] : !fir.ref<f32>, f32 |
| 50 | +! HLFIR: %[[DECL_X:.*]]:2 = hlfir.declare %[[ARG2]] {uniq_name = "_QFatomic_read_array1Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 51 | +! HLFIR: %[[DECL_R:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) {uniq_name = "_QFatomic_read_array1Er"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>) |
| 52 | +! HLFIR: %[[DES:.*]] = hlfir.designate %[[DECL_R]]#0 (%{{.*}}) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 53 | +! HLFIR: acc.atomic.read %[[DECL_X]]#1 = %[[DES]] : !fir.ref<f32>, f32 |
| 54 | + |
| 55 | +subroutine atomic_write_array1(r, n, x) |
| 56 | + implicit none |
| 57 | + integer :: n |
| 58 | + real :: r(n), x |
| 59 | + |
| 60 | + !$acc atomic write |
| 61 | + x = r(n) |
| 62 | +end subroutine |
| 63 | + |
| 64 | +! CHECK-LABEL: func.func @_QPatomic_write_array1( |
| 65 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "r"}, %[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}, %[[ARG2:.*]]: !fir.ref<f32> {fir.bindc_name = "x"}) { |
| 66 | +! FIR: %[[ARRAY_REF:.*]] = fir.coordinate_of %[[ARG0]], %{{.*}} : (!fir.ref<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 67 | +! FIR: %[[LOAD:.*]] = fir.load %[[ARRAY_REF]] : !fir.ref<f32> |
| 68 | +! FIR: acc.atomic.write %[[ARG2]] = %[[LOAD]] : !fir.ref<f32>, f32 |
| 69 | +! HLFIR: %[[DECL_X:.*]]:2 = hlfir.declare %[[ARG2]] {uniq_name = "_QFatomic_write_array1Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 70 | +! HLFIR: %[[DECL_R:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) {uniq_name = "_QFatomic_write_array1Er"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>) |
| 71 | +! HLFIR: %[[DES:.*]] = hlfir.designate %[[DECL_R]]#0 (%{{.*}}) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 72 | +! HLFIR: %[[LOAD:.*]] = fir.load %[[DES]] : !fir.ref<f32> |
| 73 | +! HLFIR: acc.atomic.write %[[DECL_X]]#1 = %[[LOAD]] : !fir.ref<f32>, f32 |
| 74 | + |
| 75 | +subroutine atomic_capture_array1(r, n, x, y) |
| 76 | + implicit none |
| 77 | + integer :: n, i |
| 78 | + real :: r(n), x, y |
| 79 | + |
| 80 | + !$acc atomic capture |
| 81 | + r(i) = r(i) + x |
| 82 | + y = r(i) |
| 83 | + !$acc end atomic |
| 84 | +end subroutine |
| 85 | + |
| 86 | +! CHECK-LABEL: func.func @_QPatomic_capture_array1( |
| 87 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "r"}, %[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}, %[[ARG2:.*]]: !fir.ref<f32> {fir.bindc_name = "x"}, %[[ARG3:.*]]: !fir.ref<f32> {fir.bindc_name = "y"}) { |
| 88 | +! HLFIR: %[[DECL_X:.*]]:2 = hlfir.declare %[[ARG2]] {uniq_name = "_QFatomic_capture_array1Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 89 | +! HLFIR: %[[DECL_Y:.*]]:2 = hlfir.declare %[[ARG3]] {uniq_name = "_QFatomic_capture_array1Ey"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 90 | +! HLFIR: %[[DECL_R:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) {uniq_name = "_QFatomic_capture_array1Er"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>) |
| 91 | +! HLFIR: %[[R_I:.*]] = hlfir.designate %[[DECL_R]]#0 (%{{.*}}) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 92 | +! FIR: %[[R_I:.*]] = fir.coordinate_of %[[ARG0]], %{{.*}} : (!fir.ref<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 93 | +! HLFIR: %[[LOAD:.*]] = fir.load %[[DECL_X]]#0 : !fir.ref<f32> |
| 94 | +! FIR: %[[LOAD:.*]] = fir.load %[[ARG2]] : !fir.ref<f32> |
| 95 | +! CHECK: acc.atomic.capture { |
| 96 | +! CHECK: acc.atomic.update %[[R_I]] : !fir.ref<f32> { |
| 97 | +! CHECK: ^bb0(%[[ARG:.*]]: f32): |
| 98 | +! CHECK: %[[ADD:.*]] = arith.addf %[[ARG]], %[[LOAD]] fastmath<contract> : f32 |
| 99 | +! CHECK: acc.yield %[[ADD]] : f32 |
| 100 | +! CHECK: } |
| 101 | +! HLFIR: acc.atomic.read %[[DECL_Y]]#1 = %[[R_I]] : !fir.ref<f32>, f32 |
| 102 | +! FIR: acc.atomic.read %[[ARG3]] = %[[R_I]] : !fir.ref<f32>, f32 |
| 103 | +! CHECK: } |
0 commit comments