[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / Intrinsics / system_clock.f90
blobade035501ea43d6aa4265658e6b96c34dc0258d8
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
3 ! CHECK-LABEL: system_clock_test
4 subroutine system_clock_test()
5 integer(4) :: c
6 integer(8) :: m
7 real :: r
8 ! CHECK-DAG: %[[c:.*]] = fir.alloca i32 {bindc_name = "c"
9 ! CHECK-DAG: %[[m:.*]] = fir.alloca i64 {bindc_name = "m"
10 ! CHECK-DAG: %[[r:.*]] = fir.alloca f32 {bindc_name = "r"
11 ! CHECK: %[[c4:.*]] = arith.constant 4 : i32
12 ! CHECK: %[[Count:.*]] = fir.call @_FortranASystemClockCount(%[[c4]]) {{.*}}: (i32) -> i64
13 ! CHECK: %[[Count1:.*]] = fir.convert %[[Count]] : (i64) -> i32
14 ! CHECK: fir.store %[[Count1]] to %[[c]] : !fir.ref<i32>
15 ! CHECK: %[[c8:.*]] = arith.constant 8 : i32
16 ! CHECK: %[[Rate:.*]] = fir.call @_FortranASystemClockCountRate(%[[c8]]) {{.*}}: (i32) -> i64
17 ! CHECK: %[[Rate1:.*]] = fir.convert %[[Rate]] : (i64) -> f32
18 ! CHECK: fir.store %[[Rate1]] to %[[r]] : !fir.ref<f32>
19 ! CHECK: %[[c8_2:.*]] = arith.constant 8 : i32
20 ! CHECK: %[[Max:.*]] = fir.call @_FortranASystemClockCountMax(%[[c8_2]]) {{.*}}: (i32) -> i64
21 ! CHECK: fir.store %[[Max]] to %[[m]] : !fir.ref<i64>
22 call system_clock(c, r, m)
23 ! print*, c, r, m
24 ! CHECK-NOT: fir.call
25 ! CHECK: %[[c8_3:.*]] = arith.constant 8 : i32
26 ! CHECK: %[[Rate:.*]] = fir.call @_FortranASystemClockCountRate(%[[c8_3]]) {{.*}}: (i32) -> i64
27 ! CHECK: fir.store %[[Rate]] to %[[m]] : !fir.ref<i64>
28 call system_clock(count_rate=m)
29 ! CHECK-NOT: fir.call
30 ! print*, m
31 end subroutine
33 ! CHECK-LABEL: @_QPss
34 subroutine ss(count)
35 ! CHECK: %[[V_0:[0-9]+]] = fir.alloca !fir.box<!fir.heap<i64>> {bindc_name = "count_max", uniq_name = "_QFssEcount_max"}
36 ! CHECK: %[[V_1:[0-9]+]] = fir.alloca !fir.heap<i64> {uniq_name = "_QFssEcount_max.addr"}
37 ! CHECK: %[[V_2:[0-9]+]] = fir.zero_bits !fir.heap<i64>
38 ! CHECK: fir.store %[[V_2]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
39 ! CHECK: %[[V_3:[0-9]+]] = fir.alloca !fir.box<!fir.ptr<i64>> {bindc_name = "count_rate", uniq_name = "_QFssEcount_rate"}
40 ! CHECK: %[[V_4:[0-9]+]] = fir.alloca !fir.ptr<i64> {uniq_name = "_QFssEcount_rate.addr"}
41 ! CHECK: %[[V_5:[0-9]+]] = fir.zero_bits !fir.ptr<i64>
42 ! CHECK: fir.store %[[V_5]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
43 ! CHECK: %[[V_6:[0-9]+]] = fir.alloca i64 {bindc_name = "count_rate_", fir.target, uniq_name = "_QFssEcount_rate_"}
44 ! CHECK: %[[V_7:[0-9]+]] = fir.convert %[[V_6]] : (!fir.ref<i64>) -> !fir.ptr<i64>
45 ! CHECK: fir.store %[[V_7]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
46 ! CHECK: %[[V_8:[0-9]+]] = fir.allocmem i64 {fir.must_be_heap = true, uniq_name = "_QFssEcount_max.alloc"}
47 ! CHECK: fir.store %[[V_8]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
48 ! CHECK: %[[V_9:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
49 ! CHECK: %[[V_10:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
50 ! CHECK: %[[V_11:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
51 ! CHECK: fir.if %[[V_11]] {
52 ! CHECK: %[[V_29:[0-9]+]] = fir.call @_FortranASystemClockCount(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
53 ! CHECK: fir.store %[[V_29]] to %arg0 : !fir.ref<i64>
54 ! CHECK: }
55 ! CHECK: %[[V_12:[0-9]+]] = fir.convert %[[V_9]] : (!fir.ptr<i64>) -> i64
56 ! CHECK: %[[V_13:[0-9]+]] = arith.cmpi ne, %[[V_12]], %c0{{.*}}_i64 : i64
57 ! CHECK: fir.if %[[V_13]] {
58 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
59 ! CHECK: fir.store %[[V_29]] to %[[V_9]] : !fir.ptr<i64>
60 ! CHECK: }
61 ! CHECK: %[[V_14:[0-9]+]] = fir.convert %[[V_10]] : (!fir.heap<i64>) -> i64
62 ! CHECK: %[[V_15:[0-9]+]] = arith.cmpi ne, %[[V_14]], %c0{{.*}}_i64_0 : i64
63 ! CHECK: fir.if %[[V_15]] {
64 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountMax(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
65 ! CHECK: fir.store %[[V_29]] to %[[V_10]] : !fir.heap<i64>
66 ! CHECK: }
67 ! CHECK: %[[V_16:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
68 ! CHECK: fir.if %[[V_16]] {
69 ! CHECK: %[[V_31:[0-9]+]] = fir.call @_FortranAioBeginExternalListOutput
70 ! CHECK: %[[V_32:[0-9]+]] = fir.load %arg0 : !fir.ref<i64>
71 ! CHECK: %[[V_33:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_32]]) {{.*}}: (!fir.ref<i8>, i64) -> i1
72 ! CHECK: %[[V_34:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
73 ! CHECK: %[[V_35:[0-9]+]] = fir.load %[[V_34]] : !fir.ptr<i64>
74 ! CHECK: %[[V_36:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_35]]) {{.*}}: (!fir.ref<i8>, i64) -> i1
75 ! CHECK: %[[V_37:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
76 ! CHECK: %[[V_38:[0-9]+]] = fir.load %[[V_37]] : !fir.heap<i64>
77 ! CHECK: %[[V_39:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_38]]) {{.*}}: (!fir.ref<i8>, i64) -> i1
78 ! CHECK: %[[V_40:[0-9]+]] = fir.call @_FortranAioEndIoStatement(%[[V_31]]) {{.*}}: (!fir.ref<i8>) -> i32
79 ! CHECK: } else {
80 ! CHECK: %[[V_29]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
81 ! CHECK: %[[V_30:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
82 ! CHECK: %[[V_31]] = fir.convert %[[V_29]] : (!fir.ptr<i64>) -> i64
83 ! CHECK: %[[V_32]] = arith.cmpi ne, %[[V_31]], %c0{{.*}}_i64_3 : i64
84 ! CHECK: fir.if %[[V_32]] {
85 ! CHECK: %[[V_45:[0-9]+]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
86 ! CHECK: fir.store %[[V_45]] to %[[V_29]] : !fir.ptr<i64>
87 ! CHECK: }
88 ! CHECK: %[[V_33]] = fir.convert %[[V_30]] : (!fir.heap<i64>) -> i64
89 ! CHECK: %[[V_34]] = arith.cmpi ne, %[[V_33]], %c0{{.*}}_i64_4 : i64
90 ! CHECK: fir.if %[[V_34]] {
91 ! CHECK: %[[V_45]] = fir.call @_FortranASystemClockCountMax(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
92 ! CHECK: fir.store %[[V_45]] to %[[V_30]] : !fir.heap<i64>
93 ! CHECK: }
94 ! CHECK: %[[V_37]] = fir.call @_FortranAioBeginExternalListOutput
95 ! CHECK: %[[V_38]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
96 ! CHECK: %[[V_39]] = fir.load %[[V_38]] : !fir.ptr<i64>
97 ! CHECK: %[[V_40]] = fir.call @_FortranAioOutputInteger64(%[[V_37]], %[[V_39]]) {{.*}}: (!fir.ref<i8>, i64) -> i1
98 ! CHECK: %[[V_41:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
99 ! CHECK: %[[V_42:[0-9]+]] = fir.load %[[V_41]] : !fir.heap<i64>
100 ! CHECK: %[[V_43:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_37]], %[[V_42]]) {{.*}}: (!fir.ref<i8>, i64) -> i1
101 ! CHECK: %[[V_44:[0-9]+]] = fir.call @_FortranAioEndIoStatement(%[[V_37]]) {{.*}}: (!fir.ref<i8>) -> i32
102 ! CHECK: }
103 ! CHECK: %[[V_17:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
104 ! CHECK: fir.if %[[V_17]] {
105 ! CHECK: %[[C_0:c[0-9a-z_]+]] = arith.constant 0 : i64
106 ! CHECK: fir.store %[[C_0]] to %arg0 : !fir.ref<i64>
107 ! CHECK: } else {
108 ! CHECK: }
109 ! CHECK: %[[V_18:[0-9]+]] = fir.zero_bits !fir.ptr<i64>
110 ! CHECK: fir.store %[[V_18]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
111 ! CHECK: %[[V_19:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
112 ! CHECK: fir.freemem %[[V_19]] : !fir.heap<i64>
113 ! CHECK: %[[V_20:[0-9]+]] = fir.zero_bits !fir.heap<i64>
114 ! CHECK: fir.store %[[V_20]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
115 ! CHECK: %[[V_21:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
116 ! CHECK: %[[V_22:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
117 ! CHECK: %[[V_23:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
118 ! CHECK: fir.if %[[V_23]] {
119 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCount(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
120 ! CHECK: fir.store %[[V_29]] to %arg0 : !fir.ref<i64>
121 ! CHECK: }
122 ! CHECK: %[[V_24:[0-9]+]] = fir.convert %[[V_21]] : (!fir.ptr<i64>) -> i64
123 ! CHECK: %[[V_25:[0-9]+]] = arith.cmpi ne, %[[V_24]], %c0{{.*}}_i64_1 : i64
124 ! CHECK: fir.if %[[V_25]] {
125 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
126 ! CHECK: fir.store %[[V_29]] to %[[V_21]] : !fir.ptr<i64>
127 ! CHECK: }
128 ! CHECK: %[[V_26:[0-9]+]] = fir.convert %[[V_22]] : (!fir.heap<i64>) -> i64
129 ! CHECK: %[[V_27:[0-9]+]] = arith.cmpi ne, %[[V_26]], %c0{{.*}}_i64_2 : i64
130 ! CHECK: fir.if %[[V_27]] {
131 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountMax(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
132 ! CHECK: fir.store %[[V_29]] to %[[V_22]] : !fir.heap<i64>
133 ! CHECK: }
134 ! CHECK: %[[V_28:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
135 ! CHECK: fir.if %[[V_28]] {
136 ! CHECK: %[[V_31]] = fir.call @_FortranAioBeginExternalListOutput
137 ! CHECK: %[[V_32]] = fir.load %arg0 : !fir.ref<i64>
138 ! CHECK: %[[V_33]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_32]]) {{.*}}: (!fir.ref<i8>, i64) -> i1
139 ! CHECK: %[[V_34]] = fir.call @_FortranAioEndIoStatement(%[[V_31]]) {{.*}}: (!fir.ref<i8>) -> i32
140 ! CHECK: } else {
141 ! CHECK: }
142 ! CHECK: return
143 ! CHECK: }
145 integer(8), optional :: count
146 integer(8), target :: count_rate_
147 integer(8), pointer :: count_rate
148 integer(8), allocatable :: count_max
150 count_rate => count_rate_
151 allocate(count_max)
152 call system_clock(count, count_rate, count_max)
153 if (present(count)) then
154 print*, count, count_rate, count_max
155 else
156 call system_clock(count_rate=count_rate, count_max=count_max)
157 print*, count_rate, count_max
158 endif
160 if (present(count)) count = 0
161 count_rate => null()
162 deallocate(count_max)
163 call system_clock(count, count_rate, count_max)
164 if (present(count)) print*, count