1 ! This test checks lowering of complex OpenACC data operands.
3 ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
5 module acc_data_operand
13 ! Testing array sections as operands
14 subroutine acc_operand_array_section()
15 real, dimension(100) :: a
17 !$acc data copyin(a(1:50)) copyout(a(51:100))
20 !CHECK-LABEL: func.func @_QMacc_data_operandPacc_operand_array_section
22 !CHECK: %[[ARR:.*]] = fir.alloca !fir.array<100xf32>
24 !CHECK: %[[C1:.*]] = arith.constant 1 : i64
25 !CHECK: %[[LB1:.*]] = fir.convert %[[C1]] : (i64) -> index
26 !CHECK: %[[C1_I64:.*]] = arith.constant 1 : i64
27 !CHECK: %[[STEP1:.*]] = fir.convert %[[C1_I64]] : (i64) -> index
28 !CHECK: %[[C50_I64:.*]] = arith.constant 50 : i64
29 !CHECK: %[[UB1:.*]] = fir.convert %[[C50_I64]] : (i64) -> index
30 !CHECK: %[[SHAPE1:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
31 !CHECK: %[[SLICE1:.*]] = fir.slice %[[LB1]], %[[UB1]], %[[STEP1]] : (index, index, index) -> !fir.slice<1>
32 !CHECK: %[[ARR_SECTION1:.*]] = fir.embox %[[ARR]](%[[SHAPE1]]) [%[[SLICE1]]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<50xf32>>
33 !CHECK: %[[MEM1:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
34 !CHECK: fir.store %[[ARR_SECTION1]] to %[[MEM1]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
36 !CHECK: %[[C51_I64:.*]] = arith.constant 51 : i64
37 !CHECK: %[[LB2:.*]] = fir.convert %[[C51_I64]] : (i64) -> index
38 !CHECK: %[[C1_I64:.*]] = arith.constant 1 : i64
39 !CHECK: %[[STEP2:.*]] = fir.convert %[[C1_I64]] : (i64) -> index
40 !CHECK: %[[C100_I64:.*]] = arith.constant 100 : i64
41 !CHECK: %[[UB2:.*]] = fir.convert %[[C100_I64]] : (i64) -> index
42 !CHECK: %[[SHAPE2:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
43 !CHECK: %[[SLICE2:.*]] = fir.slice %[[LB2]], %[[UB2]], %[[STEP2]] : (index, index, index) -> !fir.slice<1>
44 !CHECK: %[[ARR_SECTION2:.*]] = fir.embox %[[ARR]](%[[SHAPE2]]) [%[[SLICE2]]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<50xf32>>
45 !CHECK: %[[MEM2:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
46 !CHECK: fir.store %[[ARR_SECTION2]] to %[[MEM2]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
48 !CHECK: acc.data copyin(%[[MEM1]] : !fir.ref<!fir.box<!fir.array<50xf32>>>) copyout(%[[MEM2]] : !fir.ref<!fir.box<!fir.array<50xf32>>>)
52 ! Testing array sections of a derived-type component
53 subroutine acc_operand_array_section_component()
57 !$acc data copy(w%data(1:20))
60 !CHECK-LABEL: func.func @_QMacc_data_operandPacc_operand_array_section_component
61 !CHECK: %[[W:.*]] = fir.alloca !fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>
62 !CHECK: %[[FIELD_INDEX:.*]] = fir.field_index data, !fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>
63 !CHECK: %[[DATA_COORD:.*]] = fir.coordinate_of %[[W]], %[[FIELD_INDEX]] : (!fir.ref<!fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>>, !fir.field) -> !fir.ref<!fir.array<100xf32>>
64 !CHECK: %[[C1_I64_1:.*]] = arith.constant 1 : i64
65 !CHECK: %[[LB:.*]] = fir.convert %[[C1_I64_1]] : (i64) -> index
66 !CHECK: %[[C1_I64_2:.*]] = arith.constant 1 : i64
67 !CHECK: %[[STEP:.*]] = fir.convert %[[C1_I64_2]] : (i64) -> index
68 !CHECK: %[[C20_I64:.*]] = arith.constant 20 : i64
69 !CHECK: %[[UB:.*]] = fir.convert %[[C20_I64]] : (i64) -> index
70 !CHECK: %[[SHAPE:.*]] = fir.shape %{{.*}} : (index) -> !fir.shape<1>
71 !CHECK: %[[SLICE:.*]] = fir.slice %[[LB]], %[[UB]], %[[STEP]] : (index, index, index) -> !fir.slice<1>
72 !CHECK: %[[ARR_SECTION:.*]] = fir.embox %[[DATA_COORD]](%[[SHAPE]]) [%[[SLICE]]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<20xf32>>
73 !CHECK: %[[MEM:.*]] = fir.alloca !fir.box<!fir.array<20xf32>>
74 !CHECK: fir.store %[[ARR_SECTION]] to %[[MEM]] : !fir.ref<!fir.box<!fir.array<20xf32>>>
75 !CHECK: acc.data copy(%[[MEM]] : !fir.ref<!fir.box<!fir.array<20xf32>>>)
79 ! Testing derived-type component without section
80 subroutine acc_operand_derived_type_component()
83 !$acc data copy(w%data)
86 !CHECK-LABEL: func.func @_QMacc_data_operandPacc_operand_derived_type_component
87 !CHECK: %[[W:.*]] = fir.alloca !fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>
88 !CHECK: %[[FIELD_INDEX:.*]] = fir.field_index data, !fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>
89 !CHECK: %[[DATA_COORD:.*]] = fir.coordinate_of %[[W]], %[[FIELD_INDEX]] : (!fir.ref<!fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>>, !fir.field) -> !fir.ref<!fir.array<100xf32>>
90 !CHECK: acc.data copy(%[[DATA_COORD]] : !fir.ref<!fir.array<100xf32>>) {
94 ! Testing array of derived-type component without section
95 subroutine acc_operand_array_derived_type_component()
96 type(wrapper
) :: w(10)
98 !$acc data copy(w(1)%data)
101 !CHECK-LABEL: func.func @_QMacc_data_operandPacc_operand_array_derived_type_component
102 !CHECK: %[[W:.*]] = fir.alloca !fir.array<10x!fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>>
103 !CHECK: %[[C1_I64_1:.*]] = arith.constant 1 : i64
104 !CHECK: %[[C1_I64_2:.*]] = arith.constant 1 : i64
105 !CHECK: %[[IDX:.*]] = arith.subi %[[C1_I64_1]], %[[C1_I64_2]] : i64
106 !CHECK: %[[COORD1:.*]] = fir.coordinate_of %[[W]], %[[IDX]] : (!fir.ref<!fir.array<10x!fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>>>, i64) -> !fir.ref<!fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>>
107 !CHECK: %[[COORD2:.*]] = fir.field_index data, !fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>
108 !CHECK: %[[COORD_OF:.*]] = fir.coordinate_of %[[COORD1]], %[[COORD2]] : (!fir.ref<!fir.type<_QMacc_data_operandTwrapper{data:!fir.array<100xf32>}>>, !fir.field) -> !fir.ref<!fir.array<100xf32>>
109 !CHECK: acc.data copy(%[[COORD_OF]] : !fir.ref<!fir.array<100xf32>>)
113 ! Testing array sections on allocatable array
114 subroutine acc_operand_array_section_allocatable()
115 real, allocatable
:: a(:)
119 !$acc data copyin(a(1:50)) copyout(a(51:100))
122 !CHECK: %[[ARR_HEAP:.*]] = fir.alloca !fir.heap<!fir.array<?xf32>> {uniq_name = "_QMacc_data_operandFacc_operand_array_section_allocatableEa.addr"}
124 !CHECK: %[[LOAD_ARR0:.*]] = fir.load %[[ARR_HEAP]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
125 !CHECK: %[[C1_I64:.*]] = arith.constant 1 : i64
126 !CHECK: %[[LB0:.*]] = fir.convert %[[C1_I64]] : (i64) -> index
127 !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64
128 !CHECK: %[[STEP0:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index
129 !CHECK: %[[C50_I64:.*]] = arith.constant 50 : i64
130 !CHECK: %[[UB0:.*]] = fir.convert %[[C50_I64]] : (i64) -> index
131 !CHECK: %[[SHAPE_SHIFT0:.*]] = fir.shape_shift %{{.*}}, %{{.*}} : (index, index) -> !fir.shapeshift<1>
132 !CHECK: %[[SLICE0:.*]] = fir.slice %[[LB0]], %[[UB0]], %[[STEP0]] : (index, index, index) -> !fir.slice<1>
133 !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>>
134 !CHECK: %[[MEM0:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
135 !CHECK: fir.store %[[ARR_SECTION0]] to %[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
137 !CHECK: %[[LOAD_ARR1:.*]] = fir.load %[[ARR_HEAP]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>
138 !CHECK: %[[C51_I64:.*]] = arith.constant 51 : i64
139 !CHECK: %[[LB1:.*]] = fir.convert %[[C51_I64]] : (i64) -> index
140 !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64
141 !CHECK: %[[STEP1:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index
142 !CHECK: %[[C100_I64:.*]] = arith.constant 100 : i64
143 !CHECK: %[[UB1:.*]] = fir.convert %[[C100_I64]] : (i64) -> index
144 !CHECK: %[[SHAPE_SHIFT1:.*]] = fir.shape_shift %{{.*}}, %{{.*}} : (index, index) -> !fir.shapeshift<1>
145 !CHECK: %[[SLICE1:.*]] = fir.slice %[[LB1]], %[[UB1]], %[[STEP1]] : (index, index, index) -> !fir.slice<1>
146 !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>>
147 !CHECK: %[[MEM1:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
148 !CHECK: fir.store %[[ARR_SECTION1]] to %[[MEM1]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
150 !CHECK: acc.data copyin(%[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>) copyout(%[[MEM1]] : !fir.ref<!fir.box<!fir.array<50xf32>>>)
156 ! Testing array sections on pointer array
157 subroutine acc_operand_array_section_pointer()
158 real, target
:: a(100)
159 real, pointer :: p(:)
163 !$acc data copyin(p(1:50))
166 !CHECK: %[[C100:.*]] = arith.constant 100 : index
167 !CHECK: %[[ARR:.*]] = fir.alloca !fir.array<100xf32> {bindc_name = "a", fir.target, uniq_name = "_QMacc_data_operandFacc_operand_array_section_pointerEa"}
168 !CHECK: %[[PTR:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {bindc_name = "p", uniq_name = "_QMacc_data_operandFacc_operand_array_section_pointerEp"}
169 !CHECK: %[[SHAPE0:.*]] = fir.shape %[[C100]] : (index) -> !fir.shape<1>
170 !CHECK: %[[EMBOX0:.*]] = fir.embox %[[ARR]](%[[SHAPE0]]) : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
171 !CHECK: fir.store %[[EMBOX0]] to %[[PTR]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
172 !CHECK: %[[PTR_LOAD:.*]] = fir.load %[[PTR]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
173 !CHECK: %[[C0:.*]] = arith.constant 0 : index
174 !CHECK: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[PTR_LOAD]], %[[C0]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
175 !CHECK: %[[C1_I64:.*]] = arith.constant 1 : i64
176 !CHECK: %[[LB0:.*]] = fir.convert %[[C1_I64]] : (i64) -> index
177 !CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i64
178 !CHECK: %[[STEP0:.*]] = fir.convert %[[C1_STEP]] : (i64) -> index
179 !CHECK: %[[C50_I64:.*]] = arith.constant 50 : i64
180 !CHECK: %[[UB0:.*]] = fir.convert %[[C50_I64]] : (i64) -> index
181 !CHECK: %[[SHIFT0:.*]] = fir.shift %[[BOX_DIMS]]#0 : (index) -> !fir.shift<1>
182 !CHECK: %[[SLICE0:.*]] = fir.slice %[[LB0]], %[[UB0]], %[[STEP0]] : (index, index, index) -> !fir.slice<1>
183 !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>>
184 !CHECK: %[[MEM0:.*]] = fir.alloca !fir.box<!fir.array<50xf32>>
185 !CHECK: fir.store %[[REBOX0]] to %[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>
187 !CHECK: acc.data copyin(%[[MEM0]] : !fir.ref<!fir.box<!fir.array<50xf32>>>) {