1 ! This test checks the lowering of OpenMP sections construct with several clauses present
3 ! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
5 !CHECK: func @_QQmain() attributes {fir.bindc_name = "sample"} {
6 !CHECK: %[[COUNT:.*]] = fir.address_of(@_QFEcount) : !fir.ref<i32>
7 !CHECK: %[[ETA:.*]] = fir.alloca f32 {bindc_name = "eta", uniq_name = "_QFEeta"}
8 !CHECK: %[[CONST_1:.*]] = arith.constant 1 : i32
9 !CHECK: omp.sections allocate(%[[CONST_1]] : i32 -> %0 : !fir.ref<i32>) {
11 !CHECK: %[[PRIVATE_ETA:.*]] = fir.alloca f32 {bindc_name = "eta", pinned, uniq_name = "_QFEeta"}
12 !CHECK: %[[PRIVATE_DOUBLE_COUNT:.*]] = fir.alloca i32 {bindc_name = "double_count", pinned, uniq_name = "_QFEdouble_count"}
13 !CHECK: %[[const:.*]] = arith.constant 5 : i32
14 !CHECK: fir.store %[[const]] to %[[COUNT]] : !fir.ref<i32>
15 !CHECK: %[[temp_count:.*]] = fir.load %[[COUNT]] : !fir.ref<i32>
16 !CHECK: %[[temp_double_count:.*]] = fir.load %[[PRIVATE_DOUBLE_COUNT]] : !fir.ref<i32>
17 !CHECK: %[[result:.*]] = arith.muli %[[temp_count]], %[[temp_double_count]] : i32
18 !CHECK: {{.*}} = fir.convert %[[result]] : (i32) -> f32
19 !CHECK: fir.store {{.*}} to %[[PRIVATE_ETA]] : !fir.ref<f32>
20 !CHECK: omp.terminator
23 !CHECK: %[[PRIVATE_ETA:.*]] = fir.alloca f32 {bindc_name = "eta", pinned, uniq_name = "_QFEeta"}
24 !CHECK: %[[PRIVATE_DOUBLE_COUNT:.*]] = fir.alloca i32 {bindc_name = "double_count", pinned, uniq_name = "_QFEdouble_count"}
25 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_DOUBLE_COUNT]] : !fir.ref<i32>
26 !CHECK: %[[const:.*]] = arith.constant 1 : i32
27 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
28 !CHECK: fir.store %[[result]] to %[[PRIVATE_DOUBLE_COUNT]] : !fir.ref<i32>
29 !CHECK: omp.terminator
32 !CHECK: %[[PRIVATE_ETA:.*]] = fir.alloca f32 {bindc_name = "eta", pinned, uniq_name = "_QFEeta"}
33 !CHECK: %[[PRIVATE_DOUBLE_COUNT:.*]] = fir.alloca i32 {bindc_name = "double_count", pinned, uniq_name = "_QFEdouble_count"}
34 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_ETA]] : !fir.ref<f32>
35 !CHECK: %[[const:.*]] = arith.constant 7.000000e+00 : f32
36 !CHECK: %[[result:.*]] = arith.subf %[[temp]], %[[const]] {{.*}}: f32
37 !CHECK: fir.store %[[result]] to %[[PRIVATE_ETA]] : !fir.ref<f32>
38 !CHECK: {{.*}} = fir.load %[[COUNT]] : !fir.ref<i32>
39 !CHECK: %[[temp_count:.*]] = fir.convert {{.*}} : (i32) -> f32
40 !CHECK: %[[temp_eta:.*]] = fir.load %[[PRIVATE_ETA]] : !fir.ref<f32>
41 !CHECK: {{.*}} = arith.mulf %[[temp_count]], %[[temp_eta]] {{.*}}: f32
42 !CHECK: %[[result:.*]] = fir.convert {{.*}} : (f32) -> i32
43 !CHECK: fir.store %[[result]] to %[[COUNT]] : !fir.ref<i32>
44 !CHECK: {{.*}} = fir.load %[[COUNT]] : !fir.ref<i32>
45 !CHECK: %[[temp_count:.*]] = fir.convert {{.*}} : (i32) -> f32
46 !CHECK: %[[temp_eta:.*]] = fir.load %[[PRIVATE_ETA]] : !fir.ref<f32>
47 !CHECK: {{.*}} = arith.subf %[[temp_count]], %[[temp_eta]] {{.*}}: f32
48 !CHECK: %[[result:.*]] = fir.convert {{.*}} : (f32) -> i32
49 !CHECK: fir.store %[[result]] to %[[PRIVATE_DOUBLE_COUNT]] : !fir.ref<i32>
50 !CHECK: omp.terminator
52 !CHECK: omp.terminator
54 !CHECK: omp.sections nowait {
55 !CHECK: omp.terminator
62 integer :: count
= 0, double_count
= 1
63 !$omp sections private (eta, double_count) allocate(omp_high_bw_mem_alloc: count)
66 eta
= count
* double_count
68 double_count
= double_count
+ 1
72 double_count
= count
- eta
76 !$omp end sections nowait
79 !CHECK: func @_QPfirstprivate(%[[ARG:.*]]: !fir.ref<f32> {fir.bindc_name = "alpha"}) {
80 !CHECK: omp.sections {
82 !CHECK: %[[PRIVATE_ALPHA:.*]] = fir.alloca f32 {bindc_name = "alpha", pinned, uniq_name = "_QFfirstprivateEalpha"}
83 !CHECK: %[[temp:.*]] = fir.load %[[ARG]] : !fir.ref<f32>
84 !CHECK: fir.store %[[temp]] to %[[PRIVATE_ALPHA]] : !fir.ref<f32>
85 !CHECK: omp.terminator
87 !CHECK: omp.terminator
89 !CHECK: omp.sections {
91 !CHECK: %[[PRIVATE_VAR:.*]] = fir.load %[[ARG]] : !fir.ref<f32>
92 !CHECK: %[[CONSTANT:.*]] = arith.constant 5.000000e+00 : f32
93 !CHECK: %[[PRIVATE_VAR_2:.*]] = arith.mulf %[[PRIVATE_VAR]], %[[CONSTANT]] {{.*}}: f32
94 !CHECK: fir.store %[[PRIVATE_VAR_2]] to %[[ARG]] : !fir.ref<f32>
95 !CHECK: omp.terminator
97 !CHECK: omp.terminator
102 subroutine firstprivate(alpha
)
104 !$omp sections firstprivate(alpha)
112 subroutine lastprivate()
114 !CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFlastprivateEx"}
115 !CHECK: omp.sections {
116 !$omp sections lastprivate(x)
117 !CHECK: omp.section {
118 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
119 !CHECK: %[[const:.*]] = arith.constant 10 : i32
120 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
121 !CHECK: %[[result:.*]] = arith.muli %c10_i32, %[[temp]] : i32
122 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
123 !CHECK: omp.terminator
127 !CHECK: omp.section {
128 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
129 !CHECK: %[[true:.*]] = arith.constant true
130 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
131 !CHECK: %[[const:.*]] = arith.constant 1 : i32
132 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
133 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
134 !CHECK: scf.if %[[true]] {
135 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
136 !CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
138 !CHECK: omp.terminator
142 !CHECK: omp.terminator
146 !CHECK: omp.sections {
147 !$omp sections firstprivate(x) lastprivate(x)
148 !CHECK: omp.section {
149 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
150 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
151 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
153 !CHECK: %[[const:.*]] = arith.constant 10 : i32
154 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
155 !CHECK: %[[result:.*]] = arith.muli %c10_i32, %[[temp]] : i32
156 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
157 !CHECK: omp.terminator
161 !CHECK: omp.section {
162 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
163 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
164 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
166 !CHECK: %[[true:.*]] = arith.constant true
167 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
168 !CHECK: %[[const:.*]] = arith.constant 1 : i32
169 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
170 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
171 !CHECK: scf.if %true {
172 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
173 !CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
175 !CHECK: omp.terminator
179 !CHECK: omp.terminator
183 !CHECK: omp.sections nowait {
184 !$omp sections firstprivate(x) lastprivate(x)
185 !CHECK: omp.section {
186 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
187 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
188 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
190 !CHECK: %[[const:.*]] = arith.constant 10 : i32
191 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
192 !CHECK: %[[result:.*]] = arith.muli %c10_i32, %[[temp]] : i32
193 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
194 !CHECK: omp.terminator
198 !CHECK: omp.section {
199 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFlastprivateEx"}
200 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
201 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
203 !CHECK: %[[true:.*]] = arith.constant true
204 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
205 !CHECK: %[[const:.*]] = arith.constant 1 : i32
206 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
207 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
208 !CHECK: scf.if %true {
209 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
210 !CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
213 !CHECK: omp.terminator
217 !CHECK: omp.terminator
219 !$omp end sections nowait