Debian Codegraph @

flang/test/Lower/OpenMP/stop-stmt-in-region.f90

raw
1 ! This test checks lowering of stop statement in OpenMP region.
2
3 ! RUN: %flang_fc1 -flang-experimental-hlfir -emit-hlfir -fopenmp %s -o - | FileCheck %s
4 ! RUN: bbc -hlfir -emit-hlfir -fopenmp %s -o - | FileCheck %s
5
6
7 ! CHECK-LABEL: func.func @_QPtest_stop_in_region1() {
8 ! CHECK: omp.parallel {
9 ! CHECK: %[[VAL_0:.*]] = arith.constant 1 : i32
10 ! CHECK: %[[VAL_1:.*]] = arith.constant false
11 ! CHECK: %[[VAL_2:.*]] = arith.constant false
12 ! CHECK: %[[VAL_3:.*]] = fir.call @_FortranAStopStatement(%[[VAL_0]], %[[VAL_1]], %[[VAL_2]]) {{.*}} : (i32, i1, i1) -> none
13 ! CHECK-NOT: fir.unreachable
14 ! CHECK: omp.terminator
15 ! CHECK: }
16 ! CHECK: return
17 ! CHECK: }
18
19 subroutine test_stop_in_region1()
20 !$omp parallel
21 stop 1
22 !$omp end parallel
23 end
24
25 ! CHECK-LABEL: func.func @_QPtest_stop_in_region2() {
26 ! CHECK: %{{.*}} = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtest_stop_in_region2Ex"}
27 ! CHECK: omp.parallel {
28 ! CHECK: %[[VAL_1:.*]] = arith.constant 1 : i32
29 ! CHECK: %[[VAL_2:.*]] = arith.constant false
30 ! CHECK: %[[VAL_3:.*]] = arith.constant false
31 ! CHECK: %[[VAL_4:.*]] = fir.call @_FortranAStopStatement(%[[VAL_1]], %[[VAL_2]], %[[VAL_3]]) {{.*}} : (i32, i1, i1) -> none
32 ! CHECK: omp.terminator
33 ! CHECK: }
34 ! CHECK: return
35 ! CHECK: }
36
37 subroutine test_stop_in_region2()
38 integer :: x
39 !$omp parallel
40 stop 1
41 x = 2
42 !$omp end parallel
43 end
44
45 ! CHECK-LABEL: func.func @_QPtest_stop_in_region3() {
46 ! CHECK: %[[VAL_0:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtest_stop_in_region3Ex"}
47 ! CHECK: %[[VAL_0_DECL:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_stop_in_region3Ex"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
48 ! CHECK: omp.parallel {
49 ! CHECK: %[[VAL_1:.*]] = arith.constant 3 : i32
50 ! CHECK: hlfir.assign %[[VAL_1]] to %[[VAL_0_DECL]]#0 : i32, !fir.ref<i32>
51 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0_DECL]]#0 : !fir.ref<i32>
52 ! CHECK: %[[VAL_3:.*]] = arith.constant 1 : i32
53 ! CHECK: %[[VAL_4:.*]] = arith.cmpi sgt, %[[VAL_2]], %[[VAL_3]] : i32
54 ! CHECK: cf.cond_br %[[VAL_4]], ^bb1, ^bb2
55 ! CHECK: ^bb1:
56 ! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_0_DECL]]#0 : !fir.ref<i32>
57 ! CHECK: %[[VAL_6:.*]] = arith.constant false
58 ! CHECK: %[[VAL_7:.*]] = arith.constant false
59 ! CHECK: %[[VAL_8:.*]] = fir.call @_FortranAStopStatement(%[[VAL_5]], %[[VAL_6]], %[[VAL_7]]) {{.*}} : (i32, i1, i1) -> none
60 ! CHECK: omp.terminator
61 ! CHECK: ^bb2:
62 ! CHECK: omp.terminator
63 ! CHECK: }
64 ! CHECK: return
65 ! CHECK: }
66
67 subroutine test_stop_in_region3()
68 integer :: x
69 !$omp parallel
70 x = 3
71 if (x > 1) stop x
72 !$omp end parallel
73 end
74
75 ! CHECK-LABEL: func.func @_QPtest_stop_in_region4() {
76
77 ! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_stop_in_region4Ei"}
78 ! CHECK: %[[VAL_1_DECL:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFtest_stop_in_region4Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
79
80 ! CHECK: %[[VAL_2:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtest_stop_in_region4Ex"}
81 ! CHECK: %[[VAL_2_DECL:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QFtest_stop_in_region4Ex"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
82
83 ! CHECK: %[[VAL_0:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
84 ! CHECK: %[[VAL_0_DECL:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest_stop_in_region4Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
85
86 ! CHECK: %[[VAL_3:.*]] = arith.constant 1 : i32
87 ! CHECK: %[[VAL_4:.*]] = arith.constant 10 : i32
88 ! CHECK: %[[VAL_5:.*]] = arith.constant 1 : i32
89 ! CHECK: omp.wsloop {
90 ! CHECK-NEXT: omp.loop_nest (%[[VAL_6:.*]]) : i32 = (%[[VAL_3]]) to (%[[VAL_4]]) inclusive step (%[[VAL_5]]) {
91 ! CHECK: fir.store %[[VAL_6]] to %[[VAL_0_DECL]]#1 : !fir.ref<i32>
92 ! CHECK: cf.br ^bb1
93 ! CHECK: ^bb1:
94 ! CHECK: %[[VAL_7:.*]] = arith.constant 3 : i32
95 ! CHECK: hlfir.assign %[[VAL_7]] to %[[VAL_2_DECL]]#0 : i32, !fir.ref<i32>
96 ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_2_DECL]]#0 : !fir.ref<i32>
97 ! CHECK: %[[VAL_9:.*]] = arith.constant 1 : i32
98 ! CHECK: %[[VAL_10:.*]] = arith.cmpi sgt, %[[VAL_8]], %[[VAL_9]] : i32
99 ! CHECK: cf.cond_br %[[VAL_10]], ^bb2, ^bb3
100 ! CHECK: ^bb2:
101 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_2_DECL]]#0 : !fir.ref<i32>
102 ! CHECK: %[[VAL_12:.*]] = arith.constant false
103 ! CHECK: %[[VAL_13:.*]] = arith.constant false
104 ! CHECK: %[[VAL_14:.*]] = fir.call @_FortranAStopStatement(%[[VAL_11]], %[[VAL_12]], %[[VAL_13]]) {{.*}} : (i32, i1, i1) -> none
105 ! CHECK: omp.yield
106 ! CHECK: ^bb3:
107 ! CHECK: omp.yield
108 ! CHECK: }
109 ! CHECK: omp.terminator
110 ! CHECK: }
111 ! CHECK: cf.br ^bb1
112 ! CHECK: ^bb1:
113 ! CHECK: return
114 ! CHECK: }
115
116 subroutine test_stop_in_region4()
117 integer :: x
118 !$omp do
119 do i = 1, 10
120 x = 3
121 if (x > 1) stop x
122 enddo
123 !$omp end do
124 end
125
126
127 !CHECK-LABEL: func.func @_QPtest_stop_in_region5
128 !CHECK: omp.parallel {
129 !CHECK: {{.*}} fir.call @_FortranAStopStatement({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (i32, i1, i1) -> none
130 !CHECK: omp.terminator
131 !CHECK: }
132 !CHECK: return
133
134 subroutine test_stop_in_region5()
135 !$omp parallel
136 block
137 stop 1
138 end block
139 !$omp end parallel
140 end
141
142 !CHECK-LABEL: func.func @_QPtest_stop_in_region6
143 !CHECK: omp.parallel {
144 !CHECK: cf.cond_br %{{.*}}, ^[[BB1:.*]], ^[[BB2:.*]]
145 !CHECK: ^[[BB1]]:
146 !CHECK: {{.*}}fir.call @_FortranAStopStatement({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (i32, i1, i1) -> none
147 !CHECK: omp.terminator
148 !CHECK: ^[[BB2]]:
149 !CHECK: {{.*}}fir.call @_FortranAStopStatement({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (i32, i1, i1) -> none
150 !CHECK: omp.terminator
151 !CHECK: }
152 !CHECK: return
153
154 subroutine test_stop_in_region6(x)
155 integer :: x
156 !$omp parallel
157 if (x .gt. 1) then
158 stop 1
159 else
160 stop 2
161 end if
162 !$omp end parallel
163 end