Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / threadprivate-non-global.f90
blobb008bcfe21107d82a4e91cad39bd910d012818bb
1 ! This test checks lowering of OpenMP Threadprivate Directive.
2 ! Test for non-character non-SAVEd non-initialized scalars with or without
3 ! allocatable or pointer attribute in main program.
5 !RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
7 program test
8 integer :: x
9 real :: y
10 logical :: z
11 complex :: w
12 integer, pointer :: a
13 real, allocatable :: b
15 !CHECK-DAG: [[ADDR0:%.*]] = fir.address_of(@_QFEa) : !fir.ref<!fir.box<!fir.ptr<i32>>>
16 !CHECK-DAG: [[NEWADDR0:%.*]] = omp.threadprivate [[ADDR0]] : !fir.ref<!fir.box<!fir.ptr<i32>>> -> !fir.ref<!fir.box<!fir.ptr<i32>>>
17 !CHECK-DAG: [[ADDR1:%.*]] = fir.address_of(@_QFEb) : !fir.ref<!fir.box<!fir.heap<f32>>>
18 !CHECK-DAG: [[NEWADDR1:%.*]] = omp.threadprivate [[ADDR1]] : !fir.ref<!fir.box<!fir.heap<f32>>> -> !fir.ref<!fir.box<!fir.heap<f32>>>
19 !CHECK-DAG: [[ADDR2:%.*]] = fir.address_of(@_QFEw) : !fir.ref<!fir.complex<4>>
20 !CHECK-DAG: [[NEWADDR2:%.*]] = omp.threadprivate [[ADDR2]] : !fir.ref<!fir.complex<4>> -> !fir.ref<!fir.complex<4>>
21 !CHECK-DAG: [[ADDR3:%.*]] = fir.address_of(@_QFEx) : !fir.ref<i32>
22 !CHECK-DAG: [[NEWADDR3:%.*]] = omp.threadprivate [[ADDR3]] : !fir.ref<i32> -> !fir.ref<i32>
23 !CHECK-DAG: [[ADDR4:%.*]] = fir.address_of(@_QFEy) : !fir.ref<f32>
24 !CHECK-DAG: [[NEWADDR4:%.*]] = omp.threadprivate [[ADDR4]] : !fir.ref<f32> -> !fir.ref<f32>
25 !CHECK-DAG: [[ADDR5:%.*]] = fir.address_of(@_QFEz) : !fir.ref<!fir.logical<4>>
26 !CHECK-DAG: [[NEWADDR5:%.*]] = omp.threadprivate [[ADDR5]] : !fir.ref<!fir.logical<4>> -> !fir.ref<!fir.logical<4>>
27 !$omp threadprivate(x, y, z, w, a, b)
29 call sub(a, b)
31 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR3]] : !fir.ref<i32>
32 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR4]] : !fir.ref<f32>
33 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR5]] : !fir.ref<!fir.logical<4>>
34 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR2]] : !fir.ref<!fir.complex<4>>
35 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR0]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
36 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR1]] : !fir.ref<!fir.box<!fir.heap<f32>>>
37 print *, x, y, z, w, a, b
39 !$omp parallel
40 !CHECK-DAG: [[ADDR68:%.*]] = omp.threadprivate [[ADDR0]] : !fir.ref<!fir.box<!fir.ptr<i32>>> -> !fir.ref<!fir.box<!fir.ptr<i32>>>
41 !CHECK-DAG: [[ADDR69:%.*]] = omp.threadprivate [[ADDR1]] : !fir.ref<!fir.box<!fir.heap<f32>>> -> !fir.ref<!fir.box<!fir.heap<f32>>>
42 !CHECK-DAG: [[ADDR70:%.*]] = omp.threadprivate [[ADDR2]] : !fir.ref<!fir.complex<4>> -> !fir.ref<!fir.complex<4>>
43 !CHECK-DAG: [[ADDR71:%.*]] = omp.threadprivate [[ADDR3]] : !fir.ref<i32> -> !fir.ref<i32>
44 !CHECK-DAG: [[ADDR72:%.*]] = omp.threadprivate [[ADDR4]] : !fir.ref<f32> -> !fir.ref<f32>
45 !CHECK-DAG: [[ADDR73:%.*]] = omp.threadprivate [[ADDR5]] : !fir.ref<!fir.logical<4>> -> !fir.ref<!fir.logical<4>>
46 !CHECK-DAG: %{{.*}} = fir.load [[ADDR71]] : !fir.ref<i32>
47 !CHECK-DAG: %{{.*}} = fir.load [[ADDR72]] : !fir.ref<f32>
48 !CHECK-DAG: %{{.*}} = fir.load [[ADDR73]] : !fir.ref<!fir.logical<4>>
49 !CHECK-DAG: %{{.*}} = fir.load [[ADDR70]] : !fir.ref<!fir.complex<4>>
50 !CHECK-DAG: %{{.*}} = fir.load [[ADDR68]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
51 !CHECK-DAG: %{{.*}} = fir.load [[ADDR69]] : !fir.ref<!fir.box<!fir.heap<f32>>>
52 print *, x, y, z, w, a, b
53 !$omp end parallel
55 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR3]] : !fir.ref<i32>
56 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR4]] : !fir.ref<f32>
57 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR5]] : !fir.ref<!fir.logical<4>>
58 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR2]] : !fir.ref<!fir.complex<4>>
59 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR0]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
60 !CHECK-DAG: %{{.*}} = fir.load [[NEWADDR1]] : !fir.ref<!fir.box<!fir.heap<f32>>>
61 print *, x, y, z, w, a, b
63 !CHECK: return
65 !CHECK-DAG: fir.global internal @_QFEa : !fir.box<!fir.ptr<i32>> {
66 !CHECK-DAG: [[Z0:%.*]] = fir.zero_bits !fir.ptr<i32>
67 !CHECK-DAG: [[E0:%.*]] = fir.embox [[Z0]] : (!fir.ptr<i32>) -> !fir.box<!fir.ptr<i32>>
68 !CHECK-DAG: fir.has_value [[E0]] : !fir.box<!fir.ptr<i32>>
69 !CHECK-DAG: }
70 !CHECK-DAG: fir.global internal @_QFEb : !fir.box<!fir.heap<f32>> {
71 !CHECK-DAG: [[Z1:%.*]] = fir.zero_bits !fir.heap<f32>
72 !CHECK-DAG: [[E1:%.*]] = fir.embox [[Z1]] : (!fir.heap<f32>) -> !fir.box<!fir.heap<f32>>
73 !CHECK-DAG: fir.has_value [[E1]] : !fir.box<!fir.heap<f32>>
74 !CHECK-DAG: }
75 !CHECK-DAG: fir.global internal @_QFEw : !fir.complex<4> {
76 !CHECK-DAG: [[Z2:%.*]] = fir.undefined !fir.complex<4>
77 !CHECK-DAG: fir.has_value [[Z2]] : !fir.complex<4>
78 !CHECK-DAG: }
79 !CHECK-DAG: fir.global internal @_QFEx : i32 {
80 !CHECK-DAG: [[Z3:%.*]] = fir.undefined i32
81 !CHECK-DAG: fir.has_value [[Z3]] : i32
82 !CHECK-DAG: }
83 !CHECK-DAG: fir.global internal @_QFEy : f32 {
84 !CHECK-DAG: [[Z4:%.*]] = fir.undefined f32
85 !CHECK-DAG: fir.has_value [[Z4]] : f32
86 !CHECK-DAG: }
87 !CHECK-DAG: fir.global internal @_QFEz : !fir.logical<4> {
88 !CHECK-DAG: [[Z5:%.*]] = fir.undefined !fir.logical<4>
89 !CHECK-DAG: fir.has_value [[Z5]] : !fir.logical<4>
90 !CHECK-DAG: }
91 end