Skip to content

Commit 80d23ce

Browse files
author
Razvan Lupusoru
committed
[flang][acc] Add recipe populate testing through type interfaces
This PR does the following: - Updates createAndPopulate implementation so instead of first building detached blocks it directly builds them in appropriate place - because the MappableType implementation in FIR is relying on properly connected regions in order to look up module - Updates createAndPopulate to properly create destroy region with newly introduced generatePrivateDestroy API for MappableType - Adds recipe-populate-private.mlir test with comprehensive type coverage including scalars, arrays (1D/3D), derived types, and extensive box type tests (heap/ptr scalars, dynamic arrays in 1D/2D, ptr arrays, and boxed derived types) - Adds recipe-populate-firstprivate.mlir test with coverage for types with well-supported copy operations (scalars, static arrays, derived types); intentionally limits box type testing as copy implementation for complex box types is not yet complete
1 parent 8fe71e0 commit 80d23ce

File tree

3 files changed

+457
-84
lines changed

3 files changed

+457
-84
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// RUN: fir-opt %s --split-input-file --pass-pipeline="builtin.module(test-acc-recipe-populate{recipe-type=firstprivate})" | 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.firstprivate.recipe @firstprivate_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: } copy {
14+
// CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<f32>, %[[DST:.*]]: !fir.ref<f32>):
15+
// CHECK: %[[LOAD:.*]] = fir.load %[[SRC]] : !fir.ref<f32>
16+
// CHECK: fir.store %[[LOAD]] to %[[DST]] : !fir.ref<f32>
17+
// CHECK: acc.terminator
18+
// CHECK: }
19+
// CHECK-NOT: destroy
20+
21+
func.func @test_scalar() {
22+
%0 = fir.alloca f32 {test.var = "scalar"}
23+
%var = fir.alloca f32
24+
%1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
25+
return
26+
}
27+
28+
// -----
29+
30+
// Test integer scalar
31+
// CHECK: acc.firstprivate.recipe @firstprivate_int : !fir.ref<i32> init {
32+
// CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
33+
// CHECK: %[[ALLOC:.*]] = fir.alloca i32
34+
// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]] {uniq_name = "int"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
35+
// CHECK: acc.yield %{{.*}}#0 : !fir.ref<i32>
36+
// CHECK: } copy {
37+
// CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<i32>, %[[DST:.*]]: !fir.ref<i32>):
38+
// CHECK: %[[LOAD:.*]] = fir.load %[[SRC]] : !fir.ref<i32>
39+
// CHECK: fir.store %[[LOAD]] to %[[DST]] : !fir.ref<i32>
40+
// CHECK: acc.terminator
41+
// CHECK: }
42+
// CHECK-NOT: destroy
43+
44+
func.func @test_int() {
45+
%0 = fir.alloca i32 {test.var = "int"}
46+
%var = fir.alloca f32
47+
%1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
48+
return
49+
}
50+
51+
// -----
52+
53+
// Test logical type
54+
// CHECK: acc.firstprivate.recipe @firstprivate_logical : !fir.ref<!fir.logical<4>> init {
55+
// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.logical<4>>):
56+
// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.logical<4>
57+
// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]] {uniq_name = "logical"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
58+
// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.logical<4>>
59+
// CHECK: } copy {
60+
// CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<!fir.logical<4>>, %[[DST:.*]]: !fir.ref<!fir.logical<4>>):
61+
// CHECK: %[[LOAD:.*]] = fir.load %[[SRC]] : !fir.ref<!fir.logical<4>>
62+
// CHECK: fir.store %[[LOAD]] to %[[DST]] : !fir.ref<!fir.logical<4>>
63+
// CHECK: acc.terminator
64+
// CHECK: }
65+
// CHECK-NOT: destroy
66+
67+
func.func @test_logical() {
68+
%0 = fir.alloca !fir.logical<4> {test.var = "logical"}
69+
%var = fir.alloca f32
70+
%1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
71+
return
72+
}
73+
74+
// -----
75+
76+
// Test complex type
77+
// CHECK: acc.firstprivate.recipe @firstprivate_complex : !fir.ref<complex<f32>> init {
78+
// CHECK: ^bb0(%{{.*}}: !fir.ref<complex<f32>>):
79+
// CHECK: %[[ALLOC:.*]] = fir.alloca complex<f32>
80+
// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]] {uniq_name = "complex"} : (!fir.ref<complex<f32>>) -> (!fir.ref<complex<f32>>, !fir.ref<complex<f32>>)
81+
// CHECK: acc.yield %{{.*}}#0 : !fir.ref<complex<f32>>
82+
// CHECK: } copy {
83+
// CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<complex<f32>>, %[[DST:.*]]: !fir.ref<complex<f32>>):
84+
// CHECK: %[[LOAD:.*]] = fir.load %[[SRC]] : !fir.ref<complex<f32>>
85+
// CHECK: fir.store %[[LOAD]] to %[[DST]] : !fir.ref<complex<f32>>
86+
// CHECK: acc.terminator
87+
// CHECK: }
88+
// CHECK-NOT: destroy
89+
90+
func.func @test_complex() {
91+
%0 = fir.alloca complex<f32> {test.var = "complex"}
92+
%var = fir.alloca f32
93+
%1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
94+
return
95+
}
96+
97+
// -----
98+
99+
// Test 1D static array
100+
// CHECK: acc.firstprivate.recipe @firstprivate_array_1d : !fir.ref<!fir.array<100xf32>> init {
101+
// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
102+
// CHECK: %[[C100:.*]] = arith.constant 100 : index
103+
// CHECK: %[[SHAPE:.*]] = fir.shape %[[C100]] : (index) -> !fir.shape<1>
104+
// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.array<100xf32>
105+
// 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>>)
106+
// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.array<100xf32>>
107+
// CHECK: } copy {
108+
// CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<!fir.array<100xf32>>, %[[DST:.*]]: !fir.ref<!fir.array<100xf32>>):
109+
// CHECK: hlfir.assign %[[SRC]] to %[[DST]] : !fir.ref<!fir.array<100xf32>>, !fir.ref<!fir.array<100xf32>>
110+
// CHECK: acc.terminator
111+
// CHECK: }
112+
// CHECK-NOT: destroy
113+
114+
func.func @test_array_1d() {
115+
%0 = fir.alloca !fir.array<100xf32> {test.var = "array_1d"}
116+
%var = fir.alloca f32
117+
%1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
118+
return
119+
}
120+
121+
// -----
122+
123+
// Test 2D static array
124+
// CHECK: acc.firstprivate.recipe @firstprivate_array_2d : !fir.ref<!fir.array<10x20xi32>> init {
125+
// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<10x20xi32>>):
126+
// CHECK: %[[C10:.*]] = arith.constant 10 : index
127+
// CHECK: %[[C20:.*]] = arith.constant 20 : index
128+
// CHECK: %[[SHAPE:.*]] = fir.shape %[[C10]], %[[C20]] : (index, index) -> !fir.shape<2>
129+
// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.array<10x20xi32>
130+
// CHECK: %{{.*}}:2 = hlfir.declare %[[ALLOC]](%[[SHAPE]]) {uniq_name = "array_2d"} : (!fir.ref<!fir.array<10x20xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<10x20xi32>>, !fir.ref<!fir.array<10x20xi32>>)
131+
// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.array<10x20xi32>>
132+
// CHECK: } copy {
133+
// CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<!fir.array<10x20xi32>>, %[[DST:.*]]: !fir.ref<!fir.array<10x20xi32>>):
134+
// CHECK: hlfir.assign %[[SRC]] to %[[DST]] : !fir.ref<!fir.array<10x20xi32>>, !fir.ref<!fir.array<10x20xi32>>
135+
// CHECK: acc.terminator
136+
// CHECK: }
137+
// CHECK-NOT: destroy
138+
139+
func.func @test_array_2d() {
140+
%0 = fir.alloca !fir.array<10x20xi32> {test.var = "array_2d"}
141+
%var = fir.alloca f32
142+
%1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
143+
return
144+
}
145+
146+
// -----
147+
148+
// Test derived type with multiple fields
149+
// CHECK: acc.firstprivate.recipe @firstprivate_derived : !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>> init {
150+
// CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>):
151+
// CHECK: %[[ALLOC:.*]] = fir.alloca !fir.type<_QTpoint{x:f32,y:f32,z:f32}>
152+
// 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}>>)
153+
// CHECK: acc.yield %{{.*}}#0 : !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>
154+
// CHECK: } copy {
155+
// CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>, %[[DST:.*]]: !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>):
156+
// CHECK: hlfir.assign %[[SRC]] to %[[DST]] : !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>, !fir.ref<!fir.type<_QTpoint{x:f32,y:f32,z:f32}>>
157+
// CHECK: acc.terminator
158+
// CHECK: }
159+
// CHECK-NOT: destroy
160+
161+
func.func @test_derived() {
162+
%0 = fir.alloca !fir.type<_QTpoint{x:f32,y:f32,z:f32}> {test.var = "derived"}
163+
%var = fir.alloca f32
164+
%1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
165+
return
166+
}
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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

Comments
 (0)