Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / parallel-firstprivate-clause-scalar.f90
blobbd5ed5ed0fc84aca90415e5cfafb415010cca8a3
1 ! This test checks lowering of `FIRSTPRIVATE` clause for scalar types.
3 ! REQUIRES: shell
4 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s --check-prefix=FIRDialect
6 !FIRDialect-DAG: func @_QPfirstprivate_complex(%[[ARG1:.*]]: !fir.ref<!fir.complex<4>>{{.*}}, %[[ARG2:.*]]: !fir.ref<!fir.complex<8>>{{.*}}) {
7 !FIRDialect: omp.parallel {
8 !FIRDialect: %[[ARG1_PVT:.*]] = fir.alloca !fir.complex<4> {bindc_name = "arg1", pinned, uniq_name = "_QFfirstprivate_complexEarg1"}
9 !FIRDialect: %[[ARG1_VAL:.*]] = fir.load %[[ARG1]] : !fir.ref<!fir.complex<4>>
10 !FIRDialect: fir.store %[[ARG1_VAL]] to %[[ARG1_PVT]] : !fir.ref<!fir.complex<4>>
11 !FIRDialect: %[[ARG2_PVT:.*]] = fir.alloca !fir.complex<8> {bindc_name = "arg2", pinned, uniq_name = "_QFfirstprivate_complexEarg2"}
12 !FIRDialect: %[[ARG2_VAL:.*]] = fir.load %[[ARG2]] : !fir.ref<!fir.complex<8>>
13 !FIRDialect: fir.store %[[ARG2_VAL]] to %[[ARG2_PVT]] : !fir.ref<!fir.complex<8>>
14 !FIRDialect: fir.call @_QPfoo(%[[ARG1_PVT]], %[[ARG2_PVT]]) {{.*}}: (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<8>>) -> ()
15 !FIRDialect: omp.terminator
16 !FIRDialect: }
18 subroutine firstprivate_complex(arg1, arg2)
19 complex(4) :: arg1
20 complex(8) :: arg2
22 !$OMP PARALLEL FIRSTPRIVATE(arg1, arg2)
23 call foo(arg1, arg2)
24 !$OMP END PARALLEL
26 end subroutine
28 !FIRDialect-DAG: func @_QPfirstprivate_integer(%[[ARG1:.*]]: !fir.ref<i32>{{.*}}, %[[ARG2:.*]]: !fir.ref<i8>{{.*}}, %[[ARG3:.*]]: !fir.ref<i16>{{.*}}, %[[ARG4:.*]]: !fir.ref<i32>{{.*}}, %[[ARG5:.*]]: !fir.ref<i64>{{.*}}, %[[ARG6:.*]]: !fir.ref<i128>{{.*}}) {
29 !FIRDialect: omp.parallel {
30 !FIRDialect: %[[ARG1_PVT:.*]] = fir.alloca i32 {bindc_name = "arg1", pinned, uniq_name = "_QFfirstprivate_integerEarg1"}
31 !FIRDialect: %[[ARG1_VAL:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>
32 !FIRDialect: fir.store %[[ARG1_VAL]] to %[[ARG1_PVT]] : !fir.ref<i32>
33 !FIRDialect: %[[ARG2_PVT:.*]] = fir.alloca i8 {bindc_name = "arg2", pinned, uniq_name = "_QFfirstprivate_integerEarg2"}
34 !FIRDialect: %[[ARG2_VAL:.*]] = fir.load %[[ARG2]] : !fir.ref<i8>
35 !FIRDialect: fir.store %[[ARG2_VAL]] to %[[ARG2_PVT]] : !fir.ref<i8>
36 !FIRDialect: %[[ARG3_PVT:.*]] = fir.alloca i16 {bindc_name = "arg3", pinned, uniq_name = "_QFfirstprivate_integerEarg3"}
37 !FIRDialect: %[[ARG3_VAL:.*]] = fir.load %[[ARG3]] : !fir.ref<i16>
38 !FIRDialect: fir.store %[[ARG3_VAL]] to %[[ARG3_PVT]] : !fir.ref<i16>
39 !FIRDialect: %[[ARG4_PVT:.*]] = fir.alloca i32 {bindc_name = "arg4", pinned, uniq_name = "_QFfirstprivate_integerEarg4"}
40 !FIRDialect: %[[ARG4_VAL:.*]] = fir.load %[[ARG4]] : !fir.ref<i32>
41 !FIRDialect: fir.store %[[ARG4_VAL]] to %[[ARG4_PVT]] : !fir.ref<i32>
42 !FIRDialect: %[[ARG5_PVT:.*]] = fir.alloca i64 {bindc_name = "arg5", pinned, uniq_name = "_QFfirstprivate_integerEarg5"}
43 !FIRDialect: %[[ARG5_VAL:.*]] = fir.load %[[ARG5]] : !fir.ref<i64>
44 !FIRDialect: fir.store %[[ARG5_VAL]] to %[[ARG5_PVT]] : !fir.ref<i64>
45 !FIRDialect: %[[ARG6_PVT:.*]] = fir.alloca i128 {bindc_name = "arg6", pinned, uniq_name = "_QFfirstprivate_integerEarg6"}
46 !FIRDialect: %[[ARG6_VAL:.*]] = fir.load %[[ARG6]] : !fir.ref<i128>
47 !FIRDialect: fir.store %[[ARG6_VAL]] to %[[ARG6_PVT]] : !fir.ref<i128>
48 !FIRDialect: fir.call @_QPbar(%[[ARG1_PVT]], %[[ARG2_PVT]], %[[ARG3_PVT]], %[[ARG4_PVT]], %[[ARG5_PVT]], %[[ARG6_PVT]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i8>, !fir.ref<i16>, !fir.ref<i32>, !fir.ref<i64>, !fir.ref<i128>) -> ()
49 !FIRDialect: omp.terminator
50 !FIRDialect: }
52 subroutine firstprivate_integer(arg1, arg2, arg3, arg4, arg5, arg6)
53 integer :: arg1
54 integer(kind=1) :: arg2
55 integer(kind=2) :: arg3
56 integer(kind=4) :: arg4
57 integer(kind=8) :: arg5
58 integer(kind=16) :: arg6
60 !$OMP PARALLEL FIRSTPRIVATE(arg1, arg2, arg3, arg4, arg5, arg6)
61 call bar(arg1, arg2, arg3, arg4, arg5, arg6)
62 !$OMP END PARALLEL
64 end subroutine
66 !FIRDialect-DAG: func @_QPfirstprivate_logical(%[[ARG1:.*]]: !fir.ref<!fir.logical<4>>{{.*}}, %[[ARG2:.*]]: !fir.ref<!fir.logical<1>>{{.*}}, %[[ARG3:.*]]: !fir.ref<!fir.logical<2>>{{.*}}, %[[ARG4:.*]]: !fir.ref<!fir.logical<4>>{{.*}}, %[[ARG5:.*]]: !fir.ref<!fir.logical<8>>{{.*}}) {
67 !FIRDialect: omp.parallel {
68 !FIRDialect: %[[ARG1_PVT:.*]] = fir.alloca !fir.logical<4> {bindc_name = "arg1", pinned, uniq_name = "_QFfirstprivate_logicalEarg1"}
69 !FIRDialect: %[[ARG1_VAL:.*]] = fir.load %[[ARG1]] : !fir.ref<!fir.logical<4>>
70 !FIRDialect: fir.store %[[ARG1_VAL]] to %[[ARG1_PVT]] : !fir.ref<!fir.logical<4>>
71 !FIRDialect: %[[ARG2_PVT:.*]] = fir.alloca !fir.logical<1> {bindc_name = "arg2", pinned, uniq_name = "_QFfirstprivate_logicalEarg2"}
72 !FIRDialect: %[[ARG2_VAL:.*]] = fir.load %[[ARG2]] : !fir.ref<!fir.logical<1>>
73 !FIRDialect: fir.store %[[ARG2_VAL]] to %[[ARG2_PVT]] : !fir.ref<!fir.logical<1>>
74 !FIRDialect: %[[ARG3_PVT:.*]] = fir.alloca !fir.logical<2> {bindc_name = "arg3", pinned, uniq_name = "_QFfirstprivate_logicalEarg3"}
75 !FIRDialect: %[[ARG3_VAL:.*]] = fir.load %[[ARG3]] : !fir.ref<!fir.logical<2>>
76 !FIRDialect: fir.store %[[ARG3_VAL]] to %[[ARG3_PVT]] : !fir.ref<!fir.logical<2>>
77 !FIRDialect: %[[ARG4_PVT:.*]] = fir.alloca !fir.logical<4> {bindc_name = "arg4", pinned, uniq_name = "_QFfirstprivate_logicalEarg4"}
78 !FIRDialect: %[[ARG4_VAL:.*]] = fir.load %[[ARG4]] : !fir.ref<!fir.logical<4>>
79 !FIRDialect: fir.store %[[ARG4_VAL]] to %[[ARG4_PVT]] : !fir.ref<!fir.logical<4>>
80 !FIRDialect: %[[ARG5_PVT:.*]] = fir.alloca !fir.logical<8> {bindc_name = "arg5", pinned, uniq_name = "_QFfirstprivate_logicalEarg5"}
81 !FIRDialect: %[[ARG5_VAL:.*]] = fir.load %[[ARG5]] : !fir.ref<!fir.logical<8>>
82 !FIRDialect: fir.store %[[ARG5_VAL]] to %[[ARG5_PVT]] : !fir.ref<!fir.logical<8>>
83 !FIRDialect: fir.call @_QPbaz(%[[ARG1_PVT]], %[[ARG2_PVT]], %[[ARG3_PVT]], %[[ARG4_PVT]], %[[ARG5_PVT]]) {{.*}}: (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<1>>, !fir.ref<!fir.logical<2>>, !fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<8>>) -> ()
84 !FIRDialect: omp.terminator
85 !FIRDialect: }
87 subroutine firstprivate_logical(arg1, arg2, arg3, arg4, arg5)
88 logical :: arg1
89 logical(kind=1) :: arg2
90 logical(kind=2) :: arg3
91 logical(kind=4) :: arg4
92 logical(kind=8) :: arg5
94 !$OMP PARALLEL FIRSTPRIVATE(arg1, arg2, arg3, arg4, arg5)
95 call baz(arg1, arg2, arg3, arg4, arg5)
96 !$OMP END PARALLEL
98 end subroutine
100 !FIRDialect-DAG: func @_QPfirstprivate_real(%[[ARG1:.*]]: !fir.ref<f32>{{.*}}, %[[ARG2:.*]]: !fir.ref<f16>{{.*}}, %[[ARG3:.*]]: !fir.ref<f32>{{.*}}, %[[ARG4:.*]]: !fir.ref<f64>{{.*}}, %[[ARG5:.*]]: !fir.ref<f80>{{.*}}, %[[ARG6:.*]]: !fir.ref<f128>{{.*}}) {
101 !FIRDialect: omp.parallel {
102 !FIRDialect: %[[ARG1_PVT:.*]] = fir.alloca f32 {bindc_name = "arg1", pinned, uniq_name = "_QFfirstprivate_realEarg1"}
103 !FIRDialect: %[[ARG1_VAL:.*]] = fir.load %[[ARG1]] : !fir.ref<f32>
104 !FIRDialect: fir.store %[[ARG1_VAL]] to %[[ARG1_PVT]] : !fir.ref<f32>
105 !FIRDialect: %[[ARG2_PVT:.*]] = fir.alloca f16 {bindc_name = "arg2", pinned, uniq_name = "_QFfirstprivate_realEarg2"}
106 !FIRDialect: %[[ARG2_VAL:.*]] = fir.load %[[ARG2]] : !fir.ref<f16>
107 !FIRDialect: fir.store %[[ARG2_VAL]] to %[[ARG2_PVT]] : !fir.ref<f16>
108 !FIRDialect: %[[ARG3_PVT:.*]] = fir.alloca f32 {bindc_name = "arg3", pinned, uniq_name = "_QFfirstprivate_realEarg3"}
109 !FIRDialect: %[[ARG3_VAL:.*]] = fir.load %[[ARG3]] : !fir.ref<f32>
110 !FIRDialect: fir.store %[[ARG3_VAL]] to %[[ARG3_PVT]] : !fir.ref<f32>
111 !FIRDialect: %[[ARG4_PVT:.*]] = fir.alloca f64 {bindc_name = "arg4", pinned, uniq_name = "_QFfirstprivate_realEarg4"}
112 !FIRDialect: %[[ARG4_VAL:.*]] = fir.load %[[ARG4]] : !fir.ref<f64>
113 !FIRDialect: fir.store %[[ARG4_VAL]] to %[[ARG4_PVT]] : !fir.ref<f64>
114 !FIRDialect: %[[ARG5_PVT:.*]] = fir.alloca f80 {bindc_name = "arg5", pinned, uniq_name = "_QFfirstprivate_realEarg5"}
115 !FIRDialect: %[[ARG5_VAL:.*]] = fir.load %[[ARG5]] : !fir.ref<f80>
116 !FIRDialect: fir.store %[[ARG5_VAL]] to %[[ARG5_PVT]] : !fir.ref<f80>
117 !FIRDialect: %[[ARG6_PVT:.*]] = fir.alloca f128 {bindc_name = "arg6", pinned, uniq_name = "_QFfirstprivate_realEarg6"}
118 !FIRDialect: %[[ARG6_VAL:.*]] = fir.load %[[ARG6]] : !fir.ref<f128>
119 !FIRDialect: fir.store %[[ARG6_VAL]] to %[[ARG6_PVT]] : !fir.ref<f128>
120 !FIRDialect: fir.call @_QPqux(%[[ARG1_PVT]], %[[ARG2_PVT]], %[[ARG3_PVT]], %[[ARG4_PVT]], %[[ARG5_PVT]], %[[ARG6_PVT]]) {{.*}}: (!fir.ref<f32>, !fir.ref<f16>, !fir.ref<f32>, !fir.ref<f64>, !fir.ref<f80>, !fir.ref<f128>) -> ()
121 !FIRDialect: omp.terminator
122 !FIRDialect: }
124 subroutine firstprivate_real(arg1, arg2, arg3, arg4, arg5, arg6)
125 real :: arg1
126 real(kind=2) :: arg2
127 real(kind=4) :: arg3
128 real(kind=8) :: arg4
129 real(kind=10) :: arg5
130 real(kind=16) :: arg6
132 !$OMP PARALLEL FIRSTPRIVATE(arg1, arg2, arg3, arg4, arg5, arg6)
133 call qux(arg1, arg2, arg3, arg4, arg5, arg6)
134 !$OMP END PARALLEL
136 end subroutine
138 !FIRDialect-LABEL: func.func @_QPmultiple_firstprivate(
139 !FIRDialect-SAME: %[[A_ADDR:.*]]: !fir.ref<i32> {fir.bindc_name = "a"},
140 !FIRDialect-SAME: %[[B_ADDR:.*]]: !fir.ref<i32> {fir.bindc_name = "b"}) {
141 !FIRDialect: omp.parallel {
142 !FIRDialect: %[[A_PRIV_ADDR:.*]] = fir.alloca i32 {bindc_name = "a", pinned, uniq_name = "_QFmultiple_firstprivateEa"}
143 !FIRDialect: %[[A:.*]] = fir.load %[[A_ADDR]] : !fir.ref<i32>
144 !FIRDialect: fir.store %[[A]] to %[[A_PRIV_ADDR]] : !fir.ref<i32>
145 !FIRDialect: %[[B_PRIV_ADDR:.*]] = fir.alloca i32 {bindc_name = "b", pinned, uniq_name = "_QFmultiple_firstprivateEb"}
146 !FIRDialect: %[[B:.*]] = fir.load %[[B_ADDR]] : !fir.ref<i32>
147 !FIRDialect: fir.store %[[B]] to %[[B_PRIV_ADDR]] : !fir.ref<i32>
148 !FIRDialect: fir.call @_QPquux(%[[A_PRIV_ADDR]], %[[B_PRIV_ADDR]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> ()
149 !FIRDialect: omp.terminator
150 !FIRDialect: }
151 !FIRDialect: return
152 !FIRDialect: }
154 subroutine multiple_firstprivate(a, b)
155 integer :: a, b
156 !$OMP PARALLEL FIRSTPRIVATE(a) FIRSTPRIVATE(b)
157 call quux(a, b)
158 !$OMP END PARALLEL
159 end subroutine multiple_firstprivate