Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / parallel-wsloop-firstpriv.f90
blobabc0e5198c5dbab2e9b407dbeddab2ccad598ba8
1 ! This test checks lowering of OpenMP parallel DO, with the loop bound being
2 ! a firstprivate variable
4 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
6 ! CHECK: func @_QPomp_do_firstprivate(%[[ARG0:.*]]: !fir.ref<i32> {fir.bindc_name = "a"})
7 subroutine omp_do_firstprivate(a)
8 integer::a
9 integer::n
10 n = a+1
11 !$omp parallel do firstprivate(a)
12 ! CHECK: omp.parallel {
13 ! CHECK-NEXT: %[[CLONE:.*]] = fir.alloca i32 {bindc_name = "a", pinned
14 ! CHECK-NEXT: %[[LD:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
15 ! CHECK-NEXT: fir.store %[[LD]] to %[[CLONE]] : !fir.ref<i32>
16 ! CHECK-NEXT: %[[REF:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
17 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
18 ! CHECK-NEXT: %[[UB:.*]] = fir.load %[[CLONE]] : !fir.ref<i32>
19 ! CHECK-NEXT: %[[STEP:.*]] = arith.constant 1 : i32
20 ! CHECK-NEXT: omp.wsloop for (%[[ARG1:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]])
21 ! CHECK-NEXT: fir.store %[[ARG1]] to %[[REF]] : !fir.ref<i32>
22 ! CHECK-NEXT: fir.call @_QPfoo(%[[REF]], %[[CLONE]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> ()
23 ! CHECK-NEXT: omp.yield
24 do i=1, a
25 call foo(i, a)
26 end do
27 !$omp end parallel do
28 !CHECK: fir.call @_QPbar(%[[ARG0]]) {{.*}}: (!fir.ref<i32>) -> ()
29 call bar(a)
30 end subroutine omp_do_firstprivate
32 ! CHECK: func @_QPomp_do_firstprivate2(%[[ARG0:.*]]: !fir.ref<i32> {fir.bindc_name = "a"}, %[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"})
33 subroutine omp_do_firstprivate2(a, n)
34 integer::a
35 integer::n
36 n = a+1
37 !$omp parallel do firstprivate(a, n)
38 ! CHECK: omp.parallel {
39 ! CHECK-NEXT: %[[CLONE:.*]] = fir.alloca i32 {bindc_name = "a", pinned
40 ! CHECK-NEXT: %[[LD:.*]] = fir.load %[[ARG0]] : !fir.ref<i32>
41 ! CHECK-NEXT: fir.store %[[LD]] to %[[CLONE]] : !fir.ref<i32>
42 ! CHECK-NEXT: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "n", pinned
43 ! CHECK-NEXT: %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>
44 ! CHECK-NEXT: fir.store %[[LD1]] to %[[CLONE1]] : !fir.ref<i32>
45 ! CHECK-NEXT: %[[REF:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
48 ! CHECK: %[[LB:.*]] = fir.load %[[CLONE]] : !fir.ref<i32>
49 ! CHECK-NEXT: %[[UB:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
50 ! CHECK-NEXT: %[[STEP:.*]] = arith.constant 1 : i32
51 ! CHECK-NEXT: omp.wsloop for (%[[ARG2:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]])
52 ! CHECK-NEXT: fir.store %[[ARG2]] to %[[REF]] : !fir.ref<i32>
53 ! CHECK-NEXT: fir.call @_QPfoo(%[[REF]], %[[CLONE]]) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> ()
54 ! CHECK-NEXT: omp.yield
55 do i= a, n
56 call foo(i, a)
57 end do
58 !$omp end parallel do
59 !CHECK: fir.call @_QPbar(%[[ARG1]]) {{.*}}: (!fir.ref<i32>) -> ()
60 call bar(n)
61 end subroutine omp_do_firstprivate2