|
| 1 | +// RUN: fir-opt %s --split-input-file --pass-pipeline="builtin.module(test-acc-recipe-populate{recipe-type=private})" | FileCheck %s |
| 2 | + |
| 3 | +// The tests here use a synthetic hlfir.declare in order to ensure that the hlfir dialect is |
| 4 | +// loaded. This is required because the pass used is part of OpenACC test passes outside of |
| 5 | +// flang and the APIs being test may generate hlfir even when it does not appear. |
| 6 | + |
| 7 | +// Test scalar type (f32) |
| 8 | +// CHECK: acc.private.recipe @private_scalar : !fir.ref<f32> init { |
| 9 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<f32>): |
| 10 | +// CHECK: %[[ALLOC:.*]] = fir.alloca f32 |
| 11 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]] {uniq_name = "scalar"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 12 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<f32> |
| 13 | +// CHECK: } |
| 14 | +// CHECK-NOT: destroy |
| 15 | + |
| 16 | +func.func @test_scalar() { |
| 17 | + %0 = fir.alloca f32 {test.var = "scalar"} |
| 18 | + %var = fir.alloca f32 |
| 19 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 20 | + return |
| 21 | +} |
| 22 | + |
| 23 | +// ----- |
| 24 | + |
| 25 | +// Test logical type |
| 26 | +// CHECK: acc.private.recipe @private_logical : !fir.ref<!fir.logical<4>> init { |
| 27 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.logical<4>>): |
| 28 | +// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.logical<4> |
| 29 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]] {uniq_name = "logical"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>) |
| 30 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.logical<4>> |
| 31 | +// CHECK: } |
| 32 | +// CHECK-NOT: destroy |
| 33 | + |
| 34 | +func.func @test_logical() { |
| 35 | + %0 = fir.alloca !fir.logical<4> {test.var = "logical"} |
| 36 | + %var = fir.alloca f32 |
| 37 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 38 | + return |
| 39 | +} |
| 40 | + |
| 41 | +// ----- |
| 42 | + |
| 43 | +// Test complex type |
| 44 | +// CHECK: acc.private.recipe @private_complex : !fir.ref<complex<f32>> init { |
| 45 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<complex<f32>>): |
| 46 | +// CHECK: %[[ALLOC:.*]] = fir.alloca complex<f32> |
| 47 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]] {uniq_name = "complex"} : (!fir.ref<complex<f32>>) -> (!fir.ref<complex<f32>>, !fir.ref<complex<f32>>) |
| 48 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<complex<f32>> |
| 49 | +// CHECK: } |
| 50 | +// CHECK-NOT: destroy |
| 51 | + |
| 52 | +func.func @test_complex() { |
| 53 | + %0 = fir.alloca complex<f32> {test.var = "complex"} |
| 54 | + %var = fir.alloca f32 |
| 55 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 56 | + return |
| 57 | +} |
| 58 | + |
| 59 | +// ----- |
| 60 | + |
| 61 | +// Test 1D static array |
| 62 | +// CHECK: acc.private.recipe @private_array_1d : !fir.ref<!fir.array<100xf32>> init { |
| 63 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>): |
| 64 | +// CHECK: %[[C100:.*]] = arith.constant 100 : index |
| 65 | +// CHECK: %[[SHAPE:.*]] = fir.shape %[[C100]] : (index) -> !fir.shape<1> |
| 66 | +// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.array<100xf32> |
| 67 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]](%[[SHAPE]]) {uniq_name = "array_1d"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>) |
| 68 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.array<100xf32>> |
| 69 | +// CHECK: } |
| 70 | +// CHECK-NOT: destroy |
| 71 | + |
| 72 | +func.func @test_array_1d() { |
| 73 | + %0 = fir.alloca !fir.array<100xf32> {test.var = "array_1d"} |
| 74 | + %var = fir.alloca f32 |
| 75 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 76 | + return |
| 77 | +} |
| 78 | + |
| 79 | +// ----- |
| 80 | + |
| 81 | +// Test 3D static array |
| 82 | +// CHECK: acc.private.recipe @private_array_3d : !fir.ref<!fir.array<5x10x15xi32>> init { |
| 83 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<5x10x15xi32>>): |
| 84 | +// CHECK: %[[C5:.*]] = arith.constant 5 : index |
| 85 | +// CHECK: %[[C10:.*]] = arith.constant 10 : index |
| 86 | +// CHECK: %[[C15:.*]] = arith.constant 15 : index |
| 87 | +// CHECK: %[[SHAPE:.*]] = fir.shape %[[C5]], %[[C10]], %[[C15]] : (index, index, index) -> !fir.shape<3> |
| 88 | +// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.array<5x10x15xi32> |
| 89 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]](%[[SHAPE]]) {uniq_name = "array_3d"} : (!fir.ref<!fir.array<5x10x15xi32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<5x10x15xi32>>, !fir.ref<!fir.array<5x10x15xi32>>) |
| 90 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.array<5x10x15xi32>> |
| 91 | +// CHECK: } |
| 92 | +// CHECK-NOT: destroy |
| 93 | + |
| 94 | +func.func @test_array_3d() { |
| 95 | + %0 = fir.alloca !fir.array<5x10x15xi32> {test.var = "array_3d"} |
| 96 | + %var = fir.alloca f32 |
| 97 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 98 | + return |
| 99 | +} |
| 100 | + |
| 101 | +// ----- |
| 102 | + |
| 103 | +// Test derived type with multiple fields |
| 104 | +// CHECK: acc.private.recipe @private_derived : !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>> init { |
| 105 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>): |
| 106 | +// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.type<_QTpoint{x:f32,y:f32,z:f32}> |
| 107 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]] {uniq_name = "derived"} : (!fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>) -> (!fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>, !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>) |
| 108 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>> |
| 109 | +// CHECK: } |
| 110 | +// CHECK-NOT: destroy |
| 111 | + |
| 112 | +func.func @test_derived() { |
| 113 | + %0 = fir.alloca !fir.type<_QTpoint{x:f32,y:f32,z:f32}> {test.var = "derived"} |
| 114 | + %var = fir.alloca f32 |
| 115 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 116 | + return |
| 117 | +} |
| 118 | + |
| 119 | +// ----- |
| 120 | + |
| 121 | +// Test box type with heap scalar (needs destroy) |
| 122 | +// CHECK: acc.private.recipe @private_box_heap_scalar : !fir.ref<!fir.box<!fir.heap<f64>>> init { |
| 123 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.heap<f64>>>): |
| 124 | +// CHECK: %[[BOXALLOC:.*]] = fir.alloca !fir.box<!fir.heap<f64>> |
| 125 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[BOXALLOC]] {uniq_name = "box_heap_scalar"} : (!fir.ref<!fir.box<!fir.heap<f64>>>) -> (!fir.ref<!fir.box<!fir.heap<f64>>>, !fir.ref<!fir.box<!fir.heap<f64>>>) |
| 126 | +// CHECK: %[[SCALAR:.*]] = fir.allocmem f64 |
| 127 | +// CHECK: %[[EMBOX:.*]] = fir.embox %[[SCALAR]] : (!fir.heap<f64>) -> !fir.box<!fir.heap<f64>> |
| 128 | +// CHECK: fir.store %[[EMBOX]] to %{{.*}}#0 : !fir.ref<!fir.box<!fir.heap<f64>>> |
| 129 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.box<!fir.heap<f64>>> |
| 130 | +// CHECK: } destroy { |
| 131 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.heap<f64>>>, %{{.*}}: !fir.ref<!fir.box<!fir.heap<f64>>>): |
| 132 | +// CHECK: acc.terminator |
| 133 | +// CHECK: } |
| 134 | + |
| 135 | +func.func @test_box_heap_scalar() { |
| 136 | + %0 = fir.alloca !fir.box<!fir.heap<f64>> {test.var = "box_heap_scalar"} |
| 137 | + %var = fir.alloca f32 |
| 138 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 139 | + return |
| 140 | +} |
| 141 | + |
| 142 | +// ----- |
| 143 | + |
| 144 | +// Test box type with pointer scalar (needs destroy) |
| 145 | +// CHECK: acc.private.recipe @private_box_ptr_scalar : !fir.ref<!fir.box<!fir.ptr<i32>>> init { |
| 146 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.ptr<i32>>>): |
| 147 | +// CHECK: %[[BOXALLOC:.*]] = fir.alloca !fir.box<!fir.ptr<i32>> |
| 148 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[BOXALLOC]] {uniq_name = "box_ptr_scalar"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>) -> (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<!fir.box<!fir.ptr<i32>>>) |
| 149 | +// CHECK: %[[SCALAR:.*]] = fir.allocmem i32 |
| 150 | +// CHECK: %[[EMBOX:.*]] = fir.embox %[[SCALAR]] : (!fir.heap<i32>) -> !fir.box<!fir.ptr<i32>> |
| 151 | +// CHECK: fir.store %[[EMBOX]] to %{{.*}}#0 : !fir.ref<!fir.box<!fir.ptr<i32>>> |
| 152 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.box<!fir.ptr<i32>>> |
| 153 | +// CHECK: } destroy { |
| 154 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.ptr<i32>>>, %{{.*}}: !fir.ref<!fir.box<!fir.ptr<i32>>>): |
| 155 | +// CHECK: acc.terminator |
| 156 | +// CHECK: } |
| 157 | + |
| 158 | +func.func @test_box_ptr_scalar() { |
| 159 | + %0 = fir.alloca !fir.box<!fir.ptr<i32>> {test.var = "box_ptr_scalar"} |
| 160 | + %var = fir.alloca f32 |
| 161 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 162 | + return |
| 163 | +} |
| 164 | + |
| 165 | +// ----- |
| 166 | + |
| 167 | +// Test box type with 1D heap array (needs destroy) |
| 168 | +// CHECK: acc.private.recipe @private_box_heap_array_1d : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> init { |
| 169 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>): |
| 170 | +// CHECK: %[[BOXALLOC:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> |
| 171 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[BOXALLOC]] {uniq_name = "box_heap_array_1d"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>) |
| 172 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> |
| 173 | +// CHECK: } destroy { |
| 174 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, %{{.*}}: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>): |
| 175 | +// CHECK: acc.terminator |
| 176 | +// CHECK: } |
| 177 | + |
| 178 | +func.func @test_box_heap_array_1d() { |
| 179 | + %0 = fir.alloca !fir.box<!fir.heap<!fir.array<?xf32>>> {test.var = "box_heap_array_1d"} |
| 180 | + %var = fir.alloca f32 |
| 181 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 182 | + return |
| 183 | +} |
| 184 | + |
| 185 | +// ----- |
| 186 | + |
| 187 | +// Test box type with 2D heap array (needs destroy) |
| 188 | +// CHECK: acc.private.recipe @private_box_heap_array_2d : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>> init { |
| 189 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>>): |
| 190 | +// CHECK: %[[BOXALLOC:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x?xi64>>> |
| 191 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[BOXALLOC]] {uniq_name = "box_heap_array_2d"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>>) |
| 192 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>> |
| 193 | +// CHECK: } destroy { |
| 194 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>>, %{{.*}}: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi64>>>>): |
| 195 | +// CHECK: acc.terminator |
| 196 | +// CHECK: } |
| 197 | + |
| 198 | +func.func @test_box_heap_array_2d() { |
| 199 | + %0 = fir.alloca !fir.box<!fir.heap<!fir.array<?x?xi64>>> {test.var = "box_heap_array_2d"} |
| 200 | + %var = fir.alloca f32 |
| 201 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 202 | + return |
| 203 | +} |
| 204 | + |
| 205 | +// ----- |
| 206 | + |
| 207 | +// Test box type with pointer array (needs destroy) |
| 208 | +// CHECK: acc.private.recipe @private_box_ptr_array : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> init { |
| 209 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>): |
| 210 | +// CHECK: %[[BOXALLOC:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> |
| 211 | +// CHECK: %{{.*}}:2 = hlfir.declare %[[BOXALLOC]] {uniq_name = "box_ptr_array"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>) |
| 212 | +// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> |
| 213 | +// CHECK: } destroy { |
| 214 | +// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>, %{{.*}}: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>): |
| 215 | +// CHECK: acc.terminator |
| 216 | +// CHECK: } |
| 217 | + |
| 218 | +func.func @test_box_ptr_array() { |
| 219 | + %0 = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {test.var = "box_ptr_array"} |
| 220 | + %var = fir.alloca f32 |
| 221 | + %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 222 | + return |
| 223 | +} |
0 commit comments