Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / parallel.f90
blob0f20115cf66e3741feaaf46dd48a55ae397ce1d4
1 !RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
2 !RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="LLVMDialect,OMPDialect"
4 !FIRDialect-LABEL: func @_QPparallel_simple
5 subroutine parallel_simple()
6 !OMPDialect: omp.parallel
7 !$omp parallel
8 !FIRDialect: fir.call
9 call f1()
10 !$omp end parallel
11 end subroutine parallel_simple
13 !===============================================================================
14 ! `if` clause
15 !===============================================================================
17 !FIRDialect-LABEL: func @_QPparallel_if
18 subroutine parallel_if(alpha, beta, gamma)
19 integer, intent(in) :: alpha
20 logical, intent(in) :: beta
21 logical(1) :: logical1
22 logical(2) :: logical2
23 logical(4) :: logical4
24 logical(8) :: logical8
26 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
27 !$omp parallel if(alpha .le. 0)
28 !FIRDialect: fir.call
29 call f1()
30 !OMPDialect: omp.terminator
31 !$omp end parallel
33 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
34 !$omp parallel if(.false.)
35 !FIRDialect: fir.call
36 call f2()
37 !OMPDialect: omp.terminator
38 !$omp end parallel
40 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
41 !$omp parallel if(alpha .ge. 0)
42 !FIRDialect: fir.call
43 call f3()
44 !OMPDialect: omp.terminator
45 !$omp end parallel
47 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
48 !$omp parallel if(.true.)
49 !FIRDialect: fir.call
50 call f4()
51 !OMPDialect: omp.terminator
52 !$omp end parallel
54 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
55 !$omp parallel if(beta)
56 !FIRDialect: fir.call
57 call f1()
58 !OMPDialect: omp.terminator
59 !$omp end parallel
61 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
62 !$omp parallel if(logical1)
63 !FIRDialect: fir.call
64 call f1()
65 !OMPDialect: omp.terminator
66 !$omp end parallel
68 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
69 !$omp parallel if(logical2)
70 !FIRDialect: fir.call
71 call f1()
72 !OMPDialect: omp.terminator
73 !$omp end parallel
75 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
76 !$omp parallel if(logical4)
77 !FIRDialect: fir.call
78 call f1()
79 !OMPDialect: omp.terminator
80 !$omp end parallel
82 !OMPDialect: omp.parallel if(%{{.*}} : i1) {
83 !$omp parallel if(logical8)
84 !FIRDialect: fir.call
85 call f1()
86 !OMPDialect: omp.terminator
87 !$omp end parallel
89 end subroutine parallel_if
91 !===============================================================================
92 ! `num_threads` clause
93 !===============================================================================
95 !FIRDialect-LABEL: func @_QPparallel_numthreads
96 subroutine parallel_numthreads(num_threads)
97 integer, intent(inout) :: num_threads
99 !OMPDialect: omp.parallel num_threads(%{{.*}}: i32) {
100 !$omp parallel num_threads(16)
101 !FIRDialect: fir.call
102 call f1()
103 !OMPDialect: omp.terminator
104 !$omp end parallel
106 num_threads = 4
108 !OMPDialect: omp.parallel num_threads(%{{.*}} : i32) {
109 !$omp parallel num_threads(num_threads)
110 !FIRDialect: fir.call
111 call f2()
112 !OMPDialect: omp.terminator
113 !$omp end parallel
115 end subroutine parallel_numthreads
117 !===============================================================================
118 ! `proc_bind` clause
119 !===============================================================================
121 !FIRDialect-LABEL: func @_QPparallel_proc_bind
122 subroutine parallel_proc_bind()
124 !OMPDialect: omp.parallel proc_bind(master) {
125 !$omp parallel proc_bind(master)
126 !FIRDialect: fir.call
127 call f1()
128 !OMPDialect: omp.terminator
129 !$omp end parallel
131 !OMPDialect: omp.parallel proc_bind(close) {
132 !$omp parallel proc_bind(close)
133 !FIRDialect: fir.call
134 call f2()
135 !OMPDialect: omp.terminator
136 !$omp end parallel
138 !OMPDialect: omp.parallel proc_bind(spread) {
139 !$omp parallel proc_bind(spread)
140 !FIRDialect: fir.call
141 call f3()
142 !OMPDialect: omp.terminator
143 !$omp end parallel
145 end subroutine parallel_proc_bind
147 !===============================================================================
148 ! `allocate` clause
149 !===============================================================================
151 !FIRDialect-LABEL: func @_QPparallel_allocate
152 subroutine parallel_allocate()
153 use omp_lib
154 integer :: x
155 !OMPDialect: omp.parallel allocate(
156 !FIRDialect: %{{.+}} : i32 -> %{{.+}} : !fir.ref<i32>
157 !LLVMDialect: %{{.+}} : i32 -> %{{.+}} : !llvm.ptr<i32>
158 !OMPDialect: ) {
159 !$omp parallel allocate(omp_high_bw_mem_alloc: x) private(x)
160 !FIRDialect: arith.addi
161 x = x + 12
162 !OMPDialect: omp.terminator
163 !$omp end parallel
164 end subroutine parallel_allocate
166 !===============================================================================
167 ! multiple clauses
168 !===============================================================================
170 !FIRDialect-LABEL: func @_QPparallel_multiple_clauses
171 subroutine parallel_multiple_clauses(alpha, num_threads)
172 use omp_lib
173 integer, intent(inout) :: alpha
174 integer, intent(in) :: num_threads
176 !OMPDialect: omp.parallel if({{.*}} : i1) proc_bind(master) {
177 !$omp parallel if(alpha .le. 0) proc_bind(master)
178 !FIRDialect: fir.call
179 call f1()
180 !OMPDialect: omp.terminator
181 !$omp end parallel
183 !OMPDialect: omp.parallel num_threads({{.*}} : i32) proc_bind(close) {
184 !$omp parallel proc_bind(close) num_threads(num_threads)
185 !FIRDialect: fir.call
186 call f2()
187 !OMPDialect: omp.terminator
188 !$omp end parallel
190 !OMPDialect: omp.parallel if({{.*}} : i1) num_threads({{.*}} : i32) {
191 !$omp parallel num_threads(num_threads) if(alpha .le. 0)
192 !FIRDialect: fir.call
193 call f3()
194 !OMPDialect: omp.terminator
195 !$omp end parallel
197 !OMPDialect: omp.parallel if({{.*}} : i1) num_threads({{.*}} : i32) allocate(
198 !FIRDialect: %{{.+}} : i32 -> %{{.+}} : !fir.ref<i32>
199 !LLVMDialect: %{{.+}} : i32 -> %{{.+}} : !llvm.ptr<i32>
200 !OMPDialect: ) {
201 !$omp parallel num_threads(num_threads) if(alpha .le. 0) allocate(omp_high_bw_mem_alloc: alpha) private(alpha)
202 !FIRDialect: fir.call
203 call f3()
204 !FIRDialect: arith.addi
205 alpha = alpha + 12
206 !OMPDialect: omp.terminator
207 !$omp end parallel
209 end subroutine parallel_multiple_clauses