1 ! This test checks lowering of `FIRSTPRIVATE` clause for scalar types.
3 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
4 ! RUN: flang-new -fc1 -fopenmp -emit-fir %s -o - | FileCheck %s
6 !CHECK: func @_QPlastprivate_character(%[[ARG1:.*]]: !fir.boxchar<1>{{.*}}) {
7 !CHECK-DAG: %[[ARG1_UNBOX:.*]]:2 = fir.unboxchar
8 !CHECK-DAG: %[[FIVE:.*]] = arith.constant 5 : index
10 !CHECK: omp.parallel {
11 !CHECK-DAG: %[[ARG1_PVT:.*]] = fir.alloca !fir.char<1,5> {bindc_name = "arg1",
13 ! Check that we are accessing the clone inside the loop
14 !CHECK-DAG: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
15 !CHECK-DAG: %[[NEG_ONE:.*]] = arith.constant -1 : i32
16 !CHECK-NEXT: %[[ADDR:.*]] = fir.address_of(@_QQcl.
17 !CHECK-NEXT: %[[CVT0:.*]] = fir.convert %[[ADDR]]
18 !CHECK-NEXT: %[[CNST:.*]] = arith.constant
19 !CHECK-NEXT: %[[CALL_BEGIN_IO:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[NEG_ONE]], %[[CVT0]], %[[CNST]]) {{.*}}: (i32, !fir.ref<i8>, i32) -> !fir.ref<i8>
20 !CHECK-NEXT: %[[CVT_0_1:.*]] = fir.convert %[[ARG1_PVT]]
21 !CHECK-NEXT: %[[CVT_0_2:.*]] = fir.convert %[[FIVE]]
22 !CHECK-NEXT: %[[CALL_OP_ASCII:.*]] = fir.call @_FortranAioOutputAscii(%[[CALL_BEGIN_IO]], %[[CVT_0_1]], %[[CVT_0_2]])
23 !CHECK-NEXT: %[[CALL_END_IO:.*]] = fir.call @_FortranAioEndIoStatement(%[[CALL_BEGIN_IO]])
25 ! Testing last iteration check
26 !CHECK-NEXT: %[[IV_CMP:.*]] = arith.cmpi eq, %[[INDX_WS]]
27 !CHECK: scf.if %[[IV_CMP]] {
29 ! Testing lastprivate val update
30 !CHECK-DAG: %[[CVT:.*]] = fir.convert %[[ARG1_UNBOX]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
31 !CHECK-DAG: %[[CVT1:.*]] = fir.convert %[[ARG1_PVT]] : (!fir.ref<!fir.char<1,5>>) -> !fir.ref<i8>
32 !CHECK-DAG: fir.call @llvm.memmove.p0.p0.i64(%[[CVT]], %[[CVT1]]{{.*}})
36 subroutine lastprivate_character(arg1
)
39 !$OMP DO LASTPRIVATE(arg1)
48 !CHECK: func @_QPlastprivate_int(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}) {
49 !CHECK-DAG: omp.parallel {
50 !CHECK-DAG: %[[CLONE:.*]] = fir.alloca i32 {bindc_name = "arg1"
51 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
53 ! Testing last iteration check
54 !CHECK-DAG: %[[IV_CMP:.*]] = arith.cmpi eq, %[[INDX_WS]]
55 !CHECK-DAG: scf.if %[[IV_CMP]] {
57 ! Testing lastprivate val update
58 !CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE]] : !fir.ref<i32>
59 !CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG1]] : !fir.ref<i32>
63 subroutine lastprivate_int(arg1
)
66 !$OMP DO LASTPRIVATE(arg1)
76 !CHECK: func.func @_QPmult_lastprivate_int(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}, %[[ARG2:.*]]: !fir.ref<i32> {fir.bindc_name = "arg2"}) {
77 !CHECK: omp.parallel {
78 !CHECK-DAG: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
79 !CHECK-DAG: %[[CLONE2:.*]] = fir.alloca i32 {bindc_name = "arg2"
80 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
82 ! Testing last iteration check
83 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
84 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
85 ! Testing lastprivate val update
86 !CHECK-DAG: %[[CLONE_LD1:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
87 !CHECK-DAG: fir.store %[[CLONE_LD1]] to %[[ARG1]] : !fir.ref<i32>
88 !CHECK-DAG: %[[CLONE_LD2:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
89 !CHECK-DAG: fir.store %[[CLONE_LD2]] to %[[ARG2]] : !fir.ref<i32>
93 subroutine mult_lastprivate_int(arg1
, arg2
)
96 !$OMP DO LASTPRIVATE(arg1) LASTPRIVATE(arg2)
107 !CHECK: func.func @_QPmult_lastprivate_int2(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}, %[[ARG2:.*]]: !fir.ref<i32> {fir.bindc_name = "arg2"}) {
108 !CHECK: omp.parallel {
109 !CHECK-DAG: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
110 !CHECK-DAG: %[[CLONE2:.*]] = fir.alloca i32 {bindc_name = "arg2"
111 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
113 !Testing last iteration check
114 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
115 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
116 !Testing lastprivate val update
117 !CHECK-DAG: %[[CLONE_LD2:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
118 !CHECK-DAG: fir.store %[[CLONE_LD2]] to %[[ARG2]] : !fir.ref<i32>
119 !CHECK-DAG: %[[CLONE_LD1:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
120 !CHECK-DAG: fir.store %[[CLONE_LD1]] to %[[ARG1]] : !fir.ref<i32>
124 subroutine mult_lastprivate_int2(arg1
, arg2
)
125 integer :: arg1
, arg2
127 !$OMP DO LASTPRIVATE(arg1, arg2)
138 !CHECK: func.func @_QPfirstpriv_lastpriv_int(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}, %[[ARG2:.*]]: !fir.ref<i32> {fir.bindc_name = "arg2"}) {
139 !CHECK: omp.parallel {
140 ! Firstprivate update
141 !CHECK-DAG: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
142 !CHECK-DAG: %[[FPV_LD:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>
143 !CHECK-DAG: fir.store %[[FPV_LD]] to %[[CLONE1]] : !fir.ref<i32>
144 ! Lastprivate Allocation
145 !CHECK-DAG: %[[CLONE2:.*]] = fir.alloca i32 {bindc_name = "arg2"
146 !CHECK-NOT: omp.barrier
147 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
149 ! Testing last iteration check
150 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
151 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
152 ! Testing lastprivate val update
153 !CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
154 !CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG2]] : !fir.ref<i32>
156 !CHECK-NEXT: omp.yield
158 subroutine firstpriv_lastpriv_int(arg1
, arg2
)
159 integer :: arg1
, arg2
161 !$OMP DO FIRSTPRIVATE(arg1) LASTPRIVATE(arg2)
172 !CHECK: func.func @_QPfirstpriv_lastpriv_int2(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}) {
173 !CHECK: omp.parallel {
174 ! Firstprivate update
175 !CHECK-NEXT: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
176 !CHECK-NEXT: %[[FPV_LD:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>
177 !CHECK-NEXT: fir.store %[[FPV_LD]] to %[[CLONE1]] : !fir.ref<i32>
178 !CHECK-NEXT: omp.barrier
179 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
180 ! Testing last iteration check
181 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
182 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
183 ! Testing lastprivate val update
184 !CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
185 !CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG1]] : !fir.ref<i32>
187 !CHECK-NEXT: omp.yield
189 subroutine firstpriv_lastpriv_int2(arg1
)
192 !$OMP DO FIRSTPRIVATE(arg1) LASTPRIVATE(arg1)