1 ! This test checks lowering of OpenMP parallel directive
2 ! with `DEFAULT` clause present.
4 ! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
5 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
8 !CHECK: func @_QQmain() attributes {fir.bindc_name = "default_clause_lowering"} {
9 !CHECK: %[[W:.*]] = fir.alloca i32 {bindc_name = "w", uniq_name = "_QFEw"}
10 !CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
11 !CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
12 !CHECK: %[[Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFEz"}
13 !CHECK: omp.parallel {
14 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
15 !CHECK: %[[const:.*]] = fir.load %[[X]] : !fir.ref<i32>
16 !CHECK: fir.store %[[const]] to %[[PRIVATE_X]] : !fir.ref<i32>
17 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
18 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFEw"}
19 !CHECK: %[[const:.*]] = arith.constant 2 : i32
20 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
21 !CHECK: %[[result:.*]] = arith.muli %[[const]], %[[temp]] : i32
22 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
23 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_W]] : !fir.ref<i32>
24 !CHECK: %[[const:.*]] = arith.constant 45 : i32
25 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
26 !CHECK: fir.store %[[result]] to %[[Z]] : !fir.ref<i32>
27 !CHECK: omp.terminator
30 program default_clause_lowering
33 !$omp parallel default(private) firstprivate(x) shared(z)
38 !CHECK: omp.parallel {
39 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
40 !CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
41 !CHECK: omp.terminator
44 !$omp parallel default(shared)
48 !CHECK: omp.parallel {
49 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
50 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
51 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
52 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
53 !CHECK: omp.terminator
56 !$omp parallel default(none) private(x, y)
60 !CHECK: omp.parallel {
61 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
62 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
63 !CHECK: fir.store %[[temp]] to %[[PRIVATE_Y]] : !fir.ref<i32>
64 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
65 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
66 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
67 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
68 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
69 !CHECK: omp.terminator
72 !$omp parallel default(firstprivate) firstprivate(y)
76 !CHECK: omp.parallel {
77 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
78 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
79 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
80 !CHECK: fir.store %[[temp]] to %[[PRIVATE_Y]] : !fir.ref<i32>
81 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFEw"}
82 !CHECK: %[[temp:.*]] = fir.load %[[W]] : !fir.ref<i32>
83 !CHECK: fir.store %[[temp]] to %[[PRIVATE_W]] : !fir.ref<i32>
84 !CHECK: %[[const:.*]] = arith.constant 2 : i32
85 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
86 !CHECK: %[[result:.*]] = arith.muli %[[const]], %[[temp]] : i32
87 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
88 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_W]] : !fir.ref<i32>
89 !CHECK: %[[const:.*]] = arith.constant 45 : i32
90 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
91 !CHECK: fir.store %[[result]] to %[[Z]] : !fir.ref<i32>
92 !CHECK: omp.terminator
95 !$omp parallel default(firstprivate) private(x) shared(z)
100 !CHECK: omp.parallel {
101 !CHECK: omp.parallel {
102 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
103 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
104 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
105 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
106 !CHECK: omp.terminator
108 !CHECK: omp.parallel {
109 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFEw"}
110 !CHECK: %[[temp:.*]] = fir.load %[[W]] : !fir.ref<i32>
111 !CHECK: fir.store %[[temp]] to %[[PRIVATE_W]] : !fir.ref<i32>
112 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
113 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
114 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
115 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
116 !CHECK: fir.store %[[temp]] to %[[PRIVATE_W]] : !fir.ref<i32>
117 !CHECK: omp.terminator
119 !CHECK: omp.terminator
122 !$omp parallel default(private)
126 !$omp parallel default(firstprivate)
131 end program default_clause_lowering
133 subroutine nested_default_clause_tests
134 integer :: x
, y
, z
, w
, k
, a
136 !CHECK: %[[K:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFnested_default_clause_testsEk"}
137 !CHECK: %[[W:.*]] = fir.alloca i32 {bindc_name = "w", uniq_name = "_QFnested_default_clause_testsEw"}
138 !CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFnested_default_clause_testsEx"}
139 !CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFnested_default_clause_testsEy"}
140 !CHECK: %[[Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFnested_default_clause_testsEz"}
141 !CHECK: omp.parallel {
142 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
143 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
144 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
145 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
146 !CHECK: %[[PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
147 !CHECK: %[[PRIVATE_K:.*]] = fir.alloca i32 {bindc_name = "k", pinned, uniq_name = "_QFnested_default_clause_testsEk"}
148 !CHECK: omp.parallel {
149 !CHECK: %[[INNER_PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
150 !CHECK: %[[INNER_PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
151 !CHECK: %[[const:.*]] = arith.constant 20 : i32
152 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
153 !CHECK: %[[const:.*]] = arith.constant 10 : i32
154 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_X]] : !fir.ref<i32>
155 !CHECK: omp.terminator
157 !CHECK: omp.parallel {
158 !CHECK: %[[INNER_PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
159 !CHECK: %[[INNER_PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
160 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Z]]
161 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_Z]] : !fir.ref<i32>
162 !CHECK: %[[INNER_PRIVATE_K:.*]] = fir.alloca i32 {bindc_name = "k", pinned, uniq_name = "_QFnested_default_clause_testsEk"}
163 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_K]] : !fir.ref<i32>
164 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_K]] : !fir.ref<i32>
165 !CHECK: %[[const:.*]] = arith.constant 30 : i32
166 !CHECK: fir.store %[[const]] to %[[PRIVATE_Y]] : !fir.ref<i32>
167 !CHECK: %[[const:.*]] = arith.constant 40 : i32
168 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_W]] : !fir.ref<i32>
169 !CHECK: %[[const:.*]] = arith.constant 50 : i32
170 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_Z]] : !fir.ref<i32>
171 !CHECK: %[[const:.*]] = arith.constant 40 : i32
172 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_K]] : !fir.ref<i32>
173 !CHECK: omp.terminator
175 !CHECK: omp.terminator
177 !$omp parallel firstprivate(x) private(y) shared(w) default(private)
178 !$omp parallel default(private)
183 !$omp parallel default(firstprivate) shared(y) private(w)
192 !CHECK: omp.parallel {
193 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
194 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
195 !CHECK: %[[PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
196 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
197 !CHECK: omp.parallel {
198 !CHECK: %[[PRIVATE_INNER_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
199 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
200 !CHECK: fir.store %[[temp]] to %[[PRIVATE_INNER_X]] : !fir.ref<i32>
201 !CHECK: %[[INNER_PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
202 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
203 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
204 !CHECK: %[[temp:.*]] = fir.load %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
205 !CHECK: fir.store %[[temp]] to %[[PRIVATE_INNER_X]] : !fir.ref<i32>
206 !CHECK: omp.terminator
208 !CHECK: omp.parallel {
209 !CHECK: %[[PRIVATE_INNER_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
210 !CHECK: %[[PRIVATE_INNER_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
211 !CHECK: %[[temp_1:.*]] = fir.load %[[PRIVATE_INNER_X]] : !fir.ref<i32>
212 !CHECK: %[[temp_2:.*]] = fir.load %[[PRIVATE_Z]] : !fir.ref<i32>
213 !CHECK: %[[result:.*]] = arith.addi %{{.*}}, %{{.*}} : i32
214 !CHECK: fir.store %[[result]] to %[[PRIVATE_INNER_W]] : !fir.ref<i32>
215 !CHECK: omp.terminator
217 !$omp parallel default(private)
218 !$omp parallel default(firstprivate)
222 !$omp parallel default(private) shared(z)
227 !CHECK: omp.parallel {
228 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
229 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
230 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
231 !CHECK: %[[PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
232 !CHECK: omp.parallel {
233 !CHECK: %[[INNER_PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
234 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
235 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_X]] : !fir.ref<i32>
236 !CHECK: %[[INNER_PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
237 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
238 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
239 !CHECK: %[[temp:.*]] = fir.load %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
240 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_X]] : !fir.ref<i32>
241 !CHECK: omp.terminator
243 !CHECK: omp.parallel {
244 !CHECK: %[[temp_1:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
245 !CHECK: %[[temp_2:.*]] = fir.load %[[PRIVATE_Z]] : !fir.ref<i32>
246 !CHECK: %[[temp_3:.*]] = arith.addi %[[temp_1]], %[[temp_2]] : i32
247 !CHECK: fir.store %[[temp_3]] to %[[PRIVATE_W]] : !fir.ref<i32>
248 !CHECK: omp.terminator
251 !$omp parallel default(private)
252 !$omp parallel default(firstprivate)
256 !$omp parallel default(shared)
261 !CHECK: omp.parallel {
262 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
263 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
264 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
265 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
266 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
267 !CHECK: fir.store %[[temp]] to %[[PRIVATE_Y]] : !fir.ref<i32>
269 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
270 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
271 !CHECK: omp.terminator
273 !CHECK: omp.terminator
276 !$omp parallel default(firstprivate)