Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenACC / acc-loop.f90
blobac9be539cd6d37120c58ecf3b2f72a7e7c0565b9
1 ! This test checks lowering of OpenACC loop directive.
3 ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
5 program acc_loop
7 integer :: i, j
8 integer, parameter :: n = 10
9 real, dimension(n) :: a, b
10 real, dimension(n, n) :: c, d
11 integer :: gangNum = 8
12 integer :: gangStatic = 8
13 integer :: vectorLength = 128
14 integer, parameter :: tileSize = 2
17 !$acc loop
18 DO i = 1, n
19 a(i) = b(i)
20 END DO
22 !CHECK: acc.loop {
23 !CHECK: fir.do_loop
24 !CHECK: acc.yield
25 !CHECK-NEXT: }{{$}}
27 !$acc loop seq
28 DO i = 1, n
29 a(i) = b(i)
30 END DO
32 !CHECK: acc.loop {
33 !CHECK: fir.do_loop
34 !CHECK: acc.yield
35 !CHECK-NEXT: } attributes {seq}
37 !$acc loop auto
38 DO i = 1, n
39 a(i) = b(i)
40 END DO
42 !CHECK: acc.loop {
43 !CHECK: fir.do_loop
44 !CHECK: acc.yield
45 !CHECK-NEXT: } attributes {auto}
47 !$acc loop independent
48 DO i = 1, n
49 a(i) = b(i)
50 END DO
52 !CHECK: acc.loop {
53 !CHECK: fir.do_loop
54 !CHECK: acc.yield
55 !CHECK-NEXT: } attributes {independent}
57 !$acc loop gang
58 DO i = 1, n
59 a(i) = b(i)
60 END DO
62 !CHECK: acc.loop gang {
63 !CHECK: fir.do_loop
64 !CHECK: acc.yield
65 !CHECK-NEXT: }{{$}}
67 !$acc loop gang(num: 8)
68 DO i = 1, n
69 a(i) = b(i)
70 END DO
72 !CHECK: [[GANGNUM1:%.*]] = arith.constant 8 : i32
73 !CHECK-NEXT: acc.loop gang(num=[[GANGNUM1]]: i32) {
74 !CHECK: fir.do_loop
75 !CHECK: acc.yield
76 !CHECK-NEXT: }{{$}}
78 !$acc loop gang(num: gangNum)
79 DO i = 1, n
80 a(i) = b(i)
81 END DO
83 !CHECK: [[GANGNUM2:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
84 !CHECK-NEXT: acc.loop gang(num=[[GANGNUM2]]: i32) {
85 !CHECK: fir.do_loop
86 !CHECK: acc.yield
87 !CHECK-NEXT: }{{$}}
89 !$acc loop gang(num: gangNum, static: gangStatic)
90 DO i = 1, n
91 a(i) = b(i)
92 END DO
94 !CHECK: acc.loop gang(num=%{{.*}}: i32, static=%{{.*}}: i32) {
95 !CHECK: fir.do_loop
96 !CHECK: acc.yield
97 !CHECK-NEXT: }{{$}}
99 !$acc loop vector
100 DO i = 1, n
101 a(i) = b(i)
102 END DO
104 !CHECK: acc.loop vector {
105 !CHECK: fir.do_loop
106 !CHECK: acc.yield
107 !CHECK-NEXT: }{{$}}
109 !$acc loop vector(128)
110 DO i = 1, n
111 a(i) = b(i)
112 END DO
114 !CHECK: [[CONSTANT128:%.*]] = arith.constant 128 : i32
115 !CHECK: acc.loop vector([[CONSTANT128]]: i32) {
116 !CHECK: fir.do_loop
117 !CHECK: acc.yield
118 !CHECK-NEXT: }{{$}}
120 !$acc loop vector(vectorLength)
121 DO i = 1, n
122 a(i) = b(i)
123 END DO
125 !CHECK: [[VECTORLENGTH:%.*]] = fir.load %{{.*}} : !fir.ref<i32>
126 !CHECK: acc.loop vector([[VECTORLENGTH]]: i32) {
127 !CHECK: fir.do_loop
128 !CHECK: acc.yield
129 !CHECK-NEXT: }{{$}}
131 !$acc loop worker
132 DO i = 1, n
133 a(i) = b(i)
134 END DO
136 !CHECK: acc.loop worker {
137 !CHECK: fir.do_loop
138 !CHECK: acc.yield
139 !CHECK-NEXT: }{{$}}
141 !$acc loop worker(128)
142 DO i = 1, n
143 a(i) = b(i)
144 END DO
146 !CHECK: [[WORKER128:%.*]] = arith.constant 128 : i32
147 !CHECK: acc.loop worker([[WORKER128]]: i32) {
148 !CHECK: fir.do_loop
149 !CHECK: acc.yield
150 !CHECK-NEXT: }{{$}}
152 !$acc loop private(c)
153 DO i = 1, n
154 a(i) = b(i)
155 END DO
157 !CHECK: acc.loop private(%{{.*}}: !fir.ref<!fir.array<10x10xf32>>) {
158 !CHECK: fir.do_loop
159 !CHECK: acc.yield
160 !CHECK-NEXT: }{{$}}
162 !$acc loop private(c, d)
163 DO i = 1, n
164 a(i) = b(i)
165 END DO
167 !CHECK: acc.loop private(%{{.*}}: !fir.ref<!fir.array<10x10xf32>>, %{{.*}}: !fir.ref<!fir.array<10x10xf32>>) {
168 !CHECK: fir.do_loop
169 !CHECK: acc.yield
170 !CHECK-NEXT: }{{$}}
172 !$acc loop private(c) private(d)
173 DO i = 1, n
174 a(i) = b(i)
175 END DO
177 !CHECK: acc.loop private(%{{.*}}: !fir.ref<!fir.array<10x10xf32>>, %{{.*}}: !fir.ref<!fir.array<10x10xf32>>) {
178 !CHECK: fir.do_loop
179 !CHECK: acc.yield
180 !CHECK-NEXT: }{{$}}
182 !$acc loop tile(2)
183 DO i = 1, n
184 a(i) = b(i)
185 END DO
186 !CHECK: [[TILESIZE:%.*]] = arith.constant 2 : i32
187 !CHECK: acc.loop tile([[TILESIZE]]: i32) {
188 !CHECK: fir.do_loop
189 !CHECK: acc.yield
190 !CHECK-NEXT: }{{$}}
192 !$acc loop tile(*)
193 DO i = 1, n
194 a(i) = b(i)
195 END DO
196 !CHECK: [[TILESIZEM1:%.*]] = arith.constant -1 : i32
197 !CHECK: acc.loop tile([[TILESIZEM1]]: i32) {
198 !CHECK: fir.do_loop
199 !CHECK: acc.yield
200 !CHECK-NEXT: }{{$}}
202 !$acc loop tile(2, 2)
203 DO i = 1, n
204 DO j = 1, n
205 c(i, j) = d(i, j)
206 END DO
207 END DO
209 !CHECK: [[TILESIZE1:%.*]] = arith.constant 2 : i32
210 !CHECK: [[TILESIZE2:%.*]] = arith.constant 2 : i32
211 !CHECK: acc.loop tile([[TILESIZE1]]: i32, [[TILESIZE2]]: i32) {
212 !CHECK: fir.do_loop
213 !CHECK: acc.yield
214 !CHECK-NEXT: }{{$}}
216 !$acc loop tile(tileSize)
217 DO i = 1, n
218 a(i) = b(i)
219 END DO
221 !CHECK: acc.loop tile(%{{.*}}: i32) {
222 !CHECK: fir.do_loop
223 !CHECK: acc.yield
224 !CHECK-NEXT: }{{$}}
226 !$acc loop tile(tileSize, tileSize)
227 DO i = 1, n
228 DO j = 1, n
229 c(i, j) = d(i, j)
230 END DO
231 END DO
233 !CHECK: acc.loop tile(%{{.*}}: i32, %{{.*}}: i32) {
234 !CHECK: fir.do_loop
235 !CHECK: acc.yield
236 !CHECK-NEXT: }{{$}}
238 !$acc loop collapse(2)
239 DO i = 1, n
240 DO j = 1, n
241 c(i, j) = d(i, j)
242 END DO
243 END DO
245 !CHECK: acc.loop {
246 !CHECK: fir.do_loop
247 !CHECK: fir.do_loop
248 !CHECK: acc.yield
249 !CHECK-NEXT: } attributes {collapse = 2 : i64}
251 !$acc loop
252 DO i = 1, n
253 !$acc loop
254 DO j = 1, n
255 c(i, j) = d(i, j)
256 END DO
257 END DO
259 !CHECK: acc.loop {
260 !CHECK: fir.do_loop
261 !CHECK: acc.loop {
262 !CHECK: fir.do_loop
263 !CHECK: acc.yield
264 !CHECK-NEXT: }{{$}}
265 !CHECK: acc.yield
266 !CHECK-NEXT: }{{$}}
268 end program