1 // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
3 llvm.func @dealloc_foo_0(!llvm.ptr)
5 omp.private {type = private} @box.heap_privatizer0 : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> dealloc {
6 ^bb0(%arg0: !llvm.ptr):
7 llvm.call @dealloc_foo_0(%arg0) : (!llvm.ptr) -> ()
11 llvm.func @alloc_foo_1(!llvm.ptr)
12 llvm.func @dealloc_foo_1(!llvm.ptr)
14 omp.private {type = private} @box.heap_privatizer1 : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> init {
15 ^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
16 llvm.call @alloc_foo_1(%arg0) : (!llvm.ptr) -> ()
17 omp.yield(%arg1 : !llvm.ptr)
19 ^bb0(%arg0: !llvm.ptr):
20 llvm.call @dealloc_foo_1(%arg0) : (!llvm.ptr) -> ()
24 llvm.func @target_allocatable_(%arg0: !llvm.ptr {fir.bindc_name = "lb"}, %arg1: !llvm.ptr {fir.bindc_name = "ub"}, %arg2: !llvm.ptr {fir.bindc_name = "l"}) attributes {fir.internal_name = "_QPtarget_allocatable"} {
25 %6 = llvm.mlir.constant(1 : i64) : i64
26 %7 = llvm.alloca %6 x i32 {bindc_name = "mapped_var"} : (i64) -> !llvm.ptr
27 %13 = llvm.alloca %6 x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> {bindc_name = "alloc_var0"} : (i64) -> !llvm.ptr
28 %14 = llvm.alloca %6 x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> {bindc_name = "alloc_var1"} : (i64) -> !llvm.ptr
29 %53 = omp.map.info var_ptr(%7 : !llvm.ptr, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !llvm.ptr {name = "mapped_var"}
30 %54 = omp.map.info var_ptr(%13 : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(to) capture(ByRef) -> !llvm.ptr
31 %55 = omp.map.info var_ptr(%14 : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(to) capture(ByRef) -> !llvm.ptr
32 omp.target map_entries(%53 -> %arg3, %54 -> %arg4, %55 ->%arg5 : !llvm.ptr, !llvm.ptr, !llvm.ptr) private(@box.heap_privatizer0 %13 -> %arg6 [map_idx=1], @box.heap_privatizer1 %14 -> %arg7 [map_idx=2]: !llvm.ptr, !llvm.ptr) {
33 llvm.call @use_private_var0(%arg6) : (!llvm.ptr) -> ()
34 llvm.call @use_private_var1(%arg7) : (!llvm.ptr) -> ()
41 llvm.func @use_private_var0(!llvm.ptr) -> ()
42 llvm.func @use_private_var1(!llvm.ptr) -> ()
44 // The first set of checks ensure that we are calling the offloaded function
45 // with the right arguments, especially the second argument which needs to
46 // be a memory reference to the descriptor for the privatized allocatable
47 // CHECK: define void @target_allocatable_
48 // CHECK-NOT: define internal void
49 // CHECK: %[[DESC_ALLOC0:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1
50 // CHECK: %[[DESC_ALLOC1:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8 }, i64 1
51 // CHECK: call void @__omp_offloading_[[OFFLOADED_FUNCTION:.*]](ptr {{[^,]+}},
52 // CHECK-SAME: ptr %[[DESC_ALLOC0]], ptr %[[DESC_ALLOC1]])
54 // CHECK: define internal void @__omp_offloading_[[OFFLOADED_FUNCTION]]
55 // CHECK-SAME: (ptr {{[^,]+}}, ptr %[[DESCRIPTOR_ARG0:[^,]+]],
56 // CHECK-SAME: ptr %[[DESCRIPTOR_ARG1:.*]]) {
58 // `var0` privatrizer `alloc`
59 // CHECK: %[[PRIV_DESC0:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8 }
61 // `var1` privatrizer `alloc`
62 // CHECK: %[[PRIV_DESC1:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8 }
63 // CHECK: call void @alloc_foo_1(ptr %[[DESCRIPTOR_ARG1]])
66 // CHECK: call void @use_private_var0(ptr %[[PRIV_DESC0]]
67 // CHECK: call void @use_private_var1(ptr %[[PRIV_DESC1]]
69 // `var0` privatrizer `dealloc`
70 // CHECK: call void @dealloc_foo_0(ptr %[[PRIV_DESC0]])
72 // `var1` privatrizer `dealloc`
73 // CHECK: call void @dealloc_foo_1(ptr %[[PRIV_DESC1]])