92 lines · plain
1! Tests delayed privatization for `targets ... private(..)` for allocatables.2 3! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --enable-delayed-privatization-staging \4! RUN: -o - %s 2>&1 | FileCheck %s --check-prefix=CPU5 6! RUN: bbc -emit-hlfir -fopenmp --enable-delayed-privatization-staging -o - %s 2>&1 \7! RUN: | FileCheck %s --check-prefix=CPU8 9! RUN: %if amdgpu-registered-target %{ \10! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-hlfir \11! RUN: -fopenmp -fopenmp-is-target-device \12! RUN: -mmlir --enable-delayed-privatization-staging \13! RUN: -o - %s 2>&1 | \14! RUN: FileCheck %s --check-prefix=GPU \15! RUN: %}16 17! RUN: bbc -emit-hlfir -fopenmp --enable-delayed-privatization-staging \18! RUN: -fopenmp-is-target-device -fopenmp-is-gpu -o - %s 2>&1 \19! RUN: | FileCheck %s --check-prefix=GPU20 21subroutine target_allocatable22 implicit none23 integer, allocatable :: alloc_var24 25 !$omp target private(alloc_var)26 alloc_var = 1027 !$omp end target28end subroutine target_allocatable29 30! CPU-LABEL: omp.private {type = private}31! CPU-SAME: @[[VAR_PRIVATIZER_SYM:.*]] :32! CPU-SAME: [[DESC_TYPE:!fir.box<!fir.heap<i32>>]] init {33! CPU: ^bb0(%[[PRIV_ARG:.*]]: [[TYPE:!fir.ref<!fir.box<!fir.heap<i32>>>]], %[[PRIV_ALLOC:.*]]: [[TYPE]]):34 35! CPU-NEXT: %[[PRIV_ARG_VAL:.*]] = fir.load %[[PRIV_ARG]] : [[TYPE]]36! CPU-NEXT: %[[PRIV_ARG_BOX:.*]] = fir.box_addr %[[PRIV_ARG_VAL]] : ([[DESC_TYPE]]) -> !fir.heap<i32>37! CPU-NEXT: %[[PRIV_ARG_ADDR:.*]] = fir.convert %[[PRIV_ARG_BOX]] : (!fir.heap<i32>) -> i6438! CPU-NEXT: %[[C0:.*]] = arith.constant 0 : i6439! CPU-NEXT: %[[ALLOC_COND:.*]] = arith.cmpi eq, %[[PRIV_ARG_ADDR]], %[[C0]] : i6440 41! CPU-NEXT: fir.if %[[ALLOC_COND]] {42! CPU-NEXT: %[[ZERO_BOX:.*]] = fir.embox %[[PRIV_ARG_BOX]] : (!fir.heap<i32>) -> [[DESC_TYPE]]43! CPU-NEXT: fir.store %[[ZERO_BOX]] to %[[PRIV_ALLOC]] : [[TYPE]]44! CPU-NEXT: } else {45! CPU-NEXT: %[[PRIV_ALLOCMEM:.*]] = fir.allocmem i3246! CPU-NEXT: %[[PRIV_ALLOCMEM_BOX:.*]] = fir.embox %[[PRIV_ALLOCMEM]] : (!fir.heap<i32>) -> [[DESC_TYPE]]47! CPU-NEXT: fir.store %[[PRIV_ALLOCMEM_BOX]] to %[[PRIV_ALLOC]] : [[TYPE]]48! CPU-NEXT: }49 50! CPU-NEXT: omp.yield(%[[PRIV_ALLOC]] : [[TYPE]])51 52! CPU-NEXT: } dealloc {53! CPU-NEXT: ^bb0(%[[PRIV_ARG:.*]]: [[TYPE]]):54 55! CPU-NEXT: %[[PRIV_VAL:.*]] = fir.load %[[PRIV_ARG]]56! CPU-NEXT: %[[PRIV_ADDR:.*]] = fir.box_addr %[[PRIV_VAL]]57! CPU-NEXT: %[[PRIV_ADDR_I64:.*]] = fir.convert %[[PRIV_ADDR]]58! CPU-NEXT: %[[C0:.*]] = arith.constant 0 : i6459! CPU-NEXT: %[[PRIV_NULL_COND:.*]] = arith.cmpi ne, %[[PRIV_ADDR_I64]], %[[C0]] : i6460 61! CPU-NEXT: fir.if %[[PRIV_NULL_COND]] {62! CPU-NEXT: fir.freemem %[[PRIV_ADDR]]63! CPU-NEXT: }64 65! CPU-NEXT: omp.yield66! CPU-NEXT: }67 68 69! CPU-LABEL: func.func @_QPtarget_allocatable() {70 71! CPU: %[[VAR_ALLOC:.*]] = fir.alloca [[DESC_TYPE]]72! CPU-SAME: {bindc_name = "alloc_var", {{.*}}}73! CPU: %[[VAR_DECL:.*]]:2 = hlfir.declare %[[VAR_ALLOC]]74! CPU: %[[BASE_ADDR:.*]] = fir.box_offset %[[VAR_DECL]]#0 base_addr : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> [[MEMBER_TYPE:.*]]75! CPU: %[[MEMBER:.*]] = omp.map.info var_ptr(%[[VAR_DECL]]#0 : [[TYPE]], i32) map_clauses(tofrom) capture(ByRef) var_ptr_ptr(%[[BASE_ADDR]] : [[MEMBER_TYPE:.*]]) -> {{.*}}76! CPU: %[[MAP_VAR:.*]] = omp.map.info var_ptr(%[[VAR_DECL]]#0 : [[TYPE]], [[DESC_TYPE]]) map_clauses(always, to) capture(ByRef) members(%[[MEMBER]] : [0] : !fir.llvm_ptr<!fir.ref<i32>>) -> !fir.ref<!fir.box<!fir.heap<i32>>>77 78! CPU: omp.target map_entries(%[[MAP_VAR]] -> %arg0, %[[MEMBER]] -> %arg1 : [[TYPE]], [[MEMBER_TYPE]]) private(79! CPU-SAME: @[[VAR_PRIVATIZER_SYM]] %[[VAR_DECL]]#0 -> %{{.*}} [map_idx=0] : [[TYPE]]) {80 81! GPU-LABEL: omp.private {type = private} {{.*}} init {82! GPU: fir.if %{{.*}} {83! GPU-NEXT: %[[ZERO_BOX:.*]] = fir.embox %{{.*}}84! GPU-NEXT: fir.store %[[ZERO_BOX]] to %{{.*}}85! GPU-NEXT: } else {86! GPU-NOT: fir.allocmem i3287! GPU-NEXT: %[[PRIV_ALLOC:.*]] = fir.alloca i3288! GPU-NEXT: %[[PRIV_ALLOC_BOX:.*]] = fir.embox %[[PRIV_ALLOC]]89! GPU-NEXT: fir.store %[[PRIV_ALLOC_BOX]] to %{{.*}}90! GPU-NEXT: }91! GPU-NEXT: omp.yield(%{{.*}})92