[flang-commits] [flang] e114ecc - [flang][openacc][NFC] Add test with allocatable and pointer arrays

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Mon Aug 15 07:45:13 PDT 2022


Author: Valentin Clement
Date: 2022-08-15T16:45:08+02:00
New Revision: e114ecc5feafe849cbaf1a1df49dc7b3650f06ba

URL: https://github.com/llvm/llvm-project/commit/e114ecc5feafe849cbaf1a1df49dc7b3650f06ba
DIFF: https://github.com/llvm/llvm-project/commit/e114ecc5feafe849cbaf1a1df49dc7b3650f06ba.diff

LOG: [flang][openacc][NFC] Add test with allocatable and pointer arrays

This patch adds tests for the handling of array sections for
arrays with the ALLOCATABLE or POINTER attribute.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D131885

Added: 
    

Modified: 
    flang/test/Lower/OpenACC/acc-data-operands.f90

Removed: 
    


################################################################################
diff  --git a/flang/test/Lower/OpenACC/acc-data-operands.f90 b/flang/test/Lower/OpenACC/acc-data-operands.f90
index 4df81e8a1475f..002c021e8f486 100644
--- a/flang/test/Lower/OpenACC/acc-data-operands.f90
+++ b/flang/test/Lower/OpenACC/acc-data-operands.f90
@@ -113,12 +113,88 @@ subroutine acc_operand_array_derived_type_component()
 
 end subroutine
 
-subroutine acc_operand_array_section2(a)
-  real, dimension(100) :: a
+! Testing array sections on allocatable array
+subroutine acc_operand_array_section_allocatable()
+  real, allocatable :: a(:)
+
+  allocate(a(100))
+
+  !$acc data copyin(a(1:50)) copyout(a(51:100))
+  !$acc end data
+
+  !CHECK: %[[ARR_HEAP:.*]] = fir.alloca !fir.heap<!fir.array<?xf32>> {uniq_name = "_QMacc_data_operandFacc_operand_array_section_allocatableEa.addr"}
+
+  !CHECK: %[[LOAD_ARR0:.*]] = fir.load %[[ARR_HEAP]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
+  !CHECK: %[[C1_I32:.*]] = arith.constant 1 : i32
+  !CHECK: %[[C1_I64:.*]] = fir.convert %[[C1_I32]] : (i32) -> i64
+  !CHECK: %[[LB0:.*]] = fir.convert %[[C1_I64]] : (i64) -> index
+  !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64
+  !CHECK: %[[STEP0:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index
+  !CHECK: %[[C50_I32:.*]] = arith.constant 50 : i32
+  !CHECK: %[[C50_I64:.*]] = fir.convert %[[C50_I32]] : (i32) -> i64
+  !CHECK: %[[UB0:.*]] = fir.convert %[[C50_I64]] : (i64) -> index
+  !CHECK: %[[SHAPE_SHIFT0:.*]] = fir.shape_shift %{{.*}}, %{{.*}} : (index, index) -> !fir.shapeshift<1>
+  !CHECK: %[[SLICE0:.*]] = fir.slice %[[LB0]], %[[UB0]], %[[STEP0]] : (index, index, index) -> !fir.slice<1>
+  !CHECK: %[[ARR_SECTION0:.*]] = fir.embox %[[LOAD_ARR0]](%[[SHAPE_SHIFT0]]) [%[[SLICE0]]] : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<50xf32>>
+  !CHECK: %[[MEM0:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
+  !CHECK: fir.store %[[ARR_SECTION0]] to %[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
+
+  !CHECK: %[[LOAD_ARR1:.*]] = fir.load %[[ARR_HEAP]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
+  !CHECK: %[[C51_I32:.*]] = arith.constant 51 : i32
+  !CHECK: %[[C51_I64:.*]] = fir.convert %[[C51_I32]] : (i32) -> i64
+  !CHECK: %[[LB1:.*]] = fir.convert %[[C51_I64]] : (i64) -> index
+  !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64
+  !CHECK: %[[STEP1:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index
+  !CHECK: %[[C100_I32:.*]] = arith.constant 100 : i32
+  !CHECK: %[[C100_I64:.*]] = fir.convert %[[C100_I32]] : (i32) -> i64
+  !CHECK: %[[UB1:.*]] = fir.convert %[[C100_I64]] : (i64) -> index
+  !CHECK: %[[SHAPE_SHIFT1:.*]] = fir.shape_shift %{{.*}}, %{{.*}} : (index, index) -> !fir.shapeshift<1>
+  !CHECK: %[[SLICE1:.*]] = fir.slice %[[LB1]], %[[UB1]], %[[STEP1]] : (index, index, index) -> !fir.slice<1>
+  !CHECK: %[[ARR_SECTION1:.*]] = fir.embox %[[LOAD_ARR1]](%[[SHAPE_SHIFT1]]) [%[[SLICE1]]] : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<50xf32>>
+  !CHECK: %[[MEM1:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
+  !CHECK: fir.store %[[ARR_SECTION1]] to %[[MEM1]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
+
+  !CHECK: acc.data copyin(%[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>) copyout(%[[MEM1]] : !fir.ref<!fir.box<!fir.array<50xf32>>>)
+
+  deallocate(a)
+end subroutine
 
-  !$acc data copyin(a)
+
+! Testing array sections on pointer array
+subroutine acc_operand_array_section_pointer()
+  real, target :: a(100)
+  real, pointer :: p(:)
+
+  p => a
+
+  !$acc data copyin(p(1:50))
   !$acc end data
 
+  !CHECK: %[[C100:.*]] = arith.constant 100 : index
+  !CHECK: %[[ARR:.*]] = fir.alloca !fir.array<100xf32> {bindc_name = "a", fir.target, uniq_name = "_QMacc_data_operandFacc_operand_array_section_pointerEa"}
+  !CHECK: %[[PTR:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {bindc_name = "p", uniq_name = "_QMacc_data_operandFacc_operand_array_section_pointerEp"}
+  !CHECK: %[[SHAPE0:.*]] = fir.shape %[[C100]] : (index) -> !fir.shape<1>
+  !CHECK: %[[EMBOX0:.*]] = fir.embox %[[ARR]](%[[SHAPE0]]) : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
+  !CHECK: fir.store %[[EMBOX0]] to %[[PTR]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
+  !CHECK: %[[PTR_LOAD:.*]] = fir.load %[[PTR]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
+  !CHECK: %[[C0:.*]] = arith.constant 0 : index
+  !CHECK: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[PTR_LOAD]], %[[C0]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
+  !CHECK: %[[C1_I32:.*]] = arith.constant 1 : i32
+  !CHECK: %[[C1_I64:.*]] = fir.convert %[[C1_I32]] : (i32) -> i64
+  !CHECK: %[[LB0:.*]] = fir.convert %[[C1_I64]] : (i64) -> index
+  !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64
+  !CHECK: %[[STEP0:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index
+  !CHECK: %[[C50_I32:.*]] = arith.constant 50 : i32
+  !CHECK: %[[C50_I64:.*]] = fir.convert %[[C50_I32]] : (i32) -> i64
+  !CHECK: %[[UB0:.*]] = fir.convert %[[C50_I64]] : (i64) -> index
+  !CHECK: %[[SHIFT0:.*]] = fir.shift %[[BOX_DIMS]]#0 : (index) -> !fir.shift<1>
+  !CHECK: %[[SLICE0:.*]] = fir.slice %[[LB0]], %[[UB0]], %[[STEP0]] : (index, index, index) -> !fir.slice<1>
+  !CHECK: %[[REBOX0:.*]] = fir.rebox %7(%[[SHIFT0]]) [%[[SLICE0]]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<50xf32>>
+  !CHECK: %[[MEM0:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
+  !CHECK: fir.store %[[REBOX0]] to %[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
+  
+  !CHECK: acc.data copyin(%[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>) {
+
 end subroutine
 
 end module


        


More information about the flang-commits mailing list