1 ! Test unstructured code adjacent to and inside OpenMP constructs.
3 ! RUN: bbc %s -fopenmp -emit-fir -o "-" | FileCheck %s
5 ! CHECK-LABEL: func @_QPss1{{.*}} {
7 ! CHECK: ^bb1: // 2 preds: ^bb0, ^bb4
8 ! CHECK: cond_br %{{[0-9]*}}, ^bb2, ^bb5
9 ! CHECK: ^bb2: // pred: ^bb1
10 ! CHECK: cond_br %{{[0-9]*}}, ^bb3, ^bb4
11 ! CHECK: ^bb4: // pred: ^bb2
12 ! CHECK: fir.call @_FortranAioBeginExternalListOutput
14 ! CHECK: ^bb5: // 2 preds: ^bb1, ^bb3
16 ! CHECK: @_FortranAioBeginExternalListOutput
17 ! CHECK: omp.terminator
19 ! CHECK: @_FortranAioBeginExternalListOutput
21 subroutine ss1(n
) ! unstructured code followed by a structured OpenMP construct
32 ! CHECK-LABEL: func @_QPss2{{.*}} {
34 ! CHECK: @_FortranAioBeginExternalListOutput
36 ! CHECK: ^bb1: // 2 preds: ^bb0, ^bb4
37 ! CHECK: cond_br %{{[0-9]*}}, ^bb2, ^bb5
38 ! CHECK: ^bb2: // pred: ^bb1
39 ! CHECK: cond_br %{{[0-9]*}}, ^bb3, ^bb4
40 ! CHECK: ^bb3: // pred: ^bb2
41 ! CHECK: @_FortranAioBeginExternalListOutput
43 ! CHECK: ^bb5: // 2 preds: ^bb1, ^bb3
44 ! CHECK: omp.terminator
46 ! CHECK: @_FortranAioBeginExternalListOutput
47 ! CHECK: @_FortranAioBeginExternalListOutput
49 subroutine ss2(n
) ! unstructured OpenMP construct; loop exit inside construct
61 ! CHECK-LABEL: func @_QPss3{{.*}} {
62 ! CHECK: omp.parallel {
63 ! CHECK: %[[ALLOCA_K:.*]] = fir.alloca i32 {bindc_name = "k", pinned}
64 ! CHECK: %[[ALLOCA_1:.*]] = fir.alloca i32 {{{.*}}, pinned}
65 ! CHECK: %[[ALLOCA_2:.*]] = fir.alloca i32 {{{.*}}, pinned}
67 ! CHECK: ^bb1: // 2 preds: ^bb0, ^bb3
68 ! CHECK: cond_br %{{[0-9]*}}, ^bb2, ^bb4
69 ! CHECK: ^bb2: // pred: ^bb1
70 ! CHECK: omp.wsloop for (%[[ARG1:.*]]) : {{.*}} {
71 ! CHECK: fir.store %[[ARG1]] to %[[ALLOCA_2]] : !fir.ref<i32>
72 ! CHECK: @_FortranAioBeginExternalListOutput
73 ! CHECK: %[[LOAD_1:.*]] = fir.load %[[ALLOCA_2]] : !fir.ref<i32>
74 ! CHECK: @_FortranAioOutputInteger32(%{{.*}}, %[[LOAD_1]])
77 ! CHECK: omp.wsloop for (%[[ARG2:.*]]) : {{.*}} {
78 ! CHECK: fir.store %[[ARG2]] to %[[ALLOCA_1]] : !fir.ref<i32>
80 ! CHECK: ^bb2: // 2 preds: ^bb1, ^bb5
81 ! CHECK: cond_br %{{[0-9]*}}, ^bb3, ^bb6
82 ! CHECK: ^bb3: // pred: ^bb2
83 ! CHECK: cond_br %{{[0-9]*}}, ^bb4, ^bb5
84 ! CHECK: ^bb4: // pred: ^bb3
85 ! CHECK: @_FortranAioBeginExternalListOutput
86 ! CHECK: %[[LOAD_2:.*]] = fir.load %[[ALLOCA_K]] : !fir.ref<i32>
87 ! CHECK: @_FortranAioOutputInteger32(%{{.*}}, %[[LOAD_2]])
89 ! CHECK: ^bb6: // 2 preds: ^bb2, ^bb4
93 ! CHECK: ^bb4: // pred: ^bb1
94 ! CHECK: omp.terminator
97 subroutine ss3(n
) ! nested unstructured OpenMP constructs
117 ! CHECK-LABEL: func @_QPss4{{.*}} {
118 ! CHECK: omp.parallel {
119 ! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 {{{.*}}, pinned}
120 ! CHECK: omp.wsloop for (%[[ARG:.*]]) : {{.*}} {
121 ! CHECK: fir.store %[[ARG]] to %[[ALLOCA]] : !fir.ref<i32>
122 ! CHECK: %[[COND:.*]] = arith.cmpi eq, %{{.*}}, %{{.*}}
123 ! CHECK: %[[COND_XOR:.*]] = arith.xori %[[COND]], %{{.*}}
124 ! CHECK: fir.if %[[COND_XOR]] {
125 ! CHECK: @_FortranAioBeginExternalListOutput
126 ! CHECK: %[[LOAD:.*]] = fir.load %[[ALLOCA]] : !fir.ref<i32>
127 ! CHECK: @_FortranAioOutputInteger32(%{{.*}}, %[[LOAD]])
130 ! CHECK-NEXT: omp.yield
132 ! CHECK: omp.terminator
134 subroutine ss4(n
) ! CYCLE in OpenMP wsloop constructs
147 ! CHECK-LABEL: func @_QPss5() {
148 ! CHECK: omp.parallel {
149 ! CHECK: omp.wsloop {{.*}} {
150 ! CHECK: br ^[[BB1:.*]]
152 ! CHECK: br ^[[BB2:.*]]
154 ! CHECK: cond_br %{{.*}}, ^[[BB3:.*]], ^[[BB6:.*]]
156 ! CHECK: cond_br %{{.*}}, ^[[BB4:.*]], ^[[BB3:.*]]
164 ! CHECK: omp.terminator
166 subroutine ss5() ! EXIT inside OpenMP wsloop (inside parallel)
168 !$omp parallel private(x)
183 ! CHECK-LABEL: func @_QPss6() {
184 ! CHECK: omp.parallel {
185 ! CHECK: br ^[[BB1_OUTER:.*]]
186 ! CHECK: ^[[BB1_OUTER]]:
187 ! CHECK: cond_br %{{.*}}, ^[[BB2_OUTER:.*]], ^[[BB3_OUTER:.*]]
188 ! CHECK: ^[[BB2_OUTER]]:
189 ! CHECK: omp.wsloop {{.*}} {
190 ! CHECK: br ^[[BB1:.*]]
192 ! CHECK: br ^[[BB2:.*]]
194 ! CHECK: cond_br %{{.*}}, ^[[BB3:.*]], ^[[BB6:.*]]
196 ! CHECK: cond_br %{{.*}}, ^[[BB4:.*]], ^[[BB5:.*]]
204 ! CHECK: br ^[[BB1_OUTER]]
205 ! CHECK: ^[[BB3_OUTER]]:
206 ! CHECK: omp.terminator
208 subroutine ss6() ! EXIT inside OpenMP wsloop in a do loop (inside parallel)
210 !$omp parallel private(x)
227 ! CHECK-LABEL: func @_QPss7() {
228 ! CHECK: br ^[[BB1_OUTER:.*]]
229 ! CHECK: ^[[BB1_OUTER]]:
230 ! CHECK: cond_br %{{.*}}, ^[[BB2_OUTER:.*]], ^[[BB3_OUTER:.*]]
231 ! CHECK-NEXT: ^[[BB2_OUTER:.*]]:
232 ! CHECK: omp.parallel {
233 ! CHECK: omp.wsloop {{.*}} {
234 ! CHECK: br ^[[BB1:.*]]
235 ! CHECK-NEXT: ^[[BB1]]:
236 ! CHECK: br ^[[BB2:.*]]
237 ! CHECK-NEXT: ^[[BB2]]:
238 ! CHECK: cond_br %{{.*}}, ^[[BB3:.*]], ^[[BB6:.*]]
239 ! CHECK-NEXT: ^[[BB3]]:
240 ! CHECK: cond_br %{{.*}}, ^[[BB4:.*]], ^[[BB5:.*]]
241 ! CHECK-NEXT: ^[[BB4]]:
243 ! CHECK-NEXT: ^[[BB5]]:
245 ! CHECK-NEXT: ^[[BB6]]:
248 ! CHECK: omp.terminator
250 ! CHECK: br ^[[BB1_OUTER]]
251 ! CHECK-NEXT: ^[[BB3_OUTER]]:
253 subroutine ss7() ! EXIT inside OpenMP parallel do (inside do loop)
256 !$omp parallel do private(x)
265 !$omp end parallel do
269 ! CHECK-LABEL: func @_QPss8() {
270 ! CHECK: omp.parallel {
271 ! CHECK: omp.wsloop {{.*}} {
272 ! CHECK: br ^[[BB1:.*]]
273 ! CHECK-NEXT: ^[[BB1]]:
274 ! CHECK: br ^[[BB2:.*]]
276 ! CHECK: cond_br %{{.*}}, ^[[BB3:.*]], ^[[BB6:.*]]
278 ! CHECK: cond_br %{{.*}}, ^[[BB4:.*]], ^[[BB5:.*]]
280 ! CHECK-NEXT: br ^[[BB6]]
283 ! CHECK-NEXT: ^[[BB6]]:
286 ! CHECK: omp.terminator
288 subroutine ss8() ! EXIT inside OpenMP parallel do
290 !$omp parallel do private(x)
299 !$omp end parallel do
302 ! CHECK-LABEL: func @_QPss9() {
303 ! CHECK: omp.parallel {
304 ! CHECK-NEXT: omp.parallel {
305 ! CHECK: br ^[[BB1:.*]]
307 ! CHECK: cond_br %{{.*}}, ^[[BB2:.*]], ^[[BB5:.*]]
308 ! CHECK-NEXT: ^[[BB2]]:
309 ! CHECK: cond_br %{{.*}}, ^[[BB3:.*]], ^[[BB4:.*]]
310 ! CHECK-NEXT: ^[[BB3]]:
311 ! CHECK-NEXT: br ^[[BB5]]
312 ! CHECK-NEXT: ^[[BB4]]:
314 ! CHECK-NEXT: ^[[BB5]]:
315 ! CHECK: omp.terminator
317 ! CHECK: omp.terminator
320 subroutine ss9() ! EXIT inside OpenMP parallel (inside parallel)
323 !$omp parallel private(x)
333 ! CHECK-LABEL: func @_QQmain