1 ! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false %s -o - | FileCheck %s
3 ! CHECK-LABEL: system_clock_test
4 subroutine system_clock_test()
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
)
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
)
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>
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
57 ! CHECK: fir.if %[[V_13]] {
58 ! CHECK: %[[V_29:[0-9]+]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
59 ! CHECK: fir.store %[[V_29]] to %[[V_9]] : !fir.ptr<i64>
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
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>
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
80 ! CHECK: %[[V_29:[0-9]+]] = 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:[0-9]+]] = fir.convert %[[V_29]] : (!fir.ptr<i64>) -> i64
83 ! CHECK: %[[V_32:[0-9]+]] = arith.cmpi ne, %[[V_31]], %c0{{.*}} : 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>
88 ! CHECK: %[[V_33:[0-9]+]] = fir.convert %[[V_30]] : (!fir.heap<i64>) -> i64
89 ! CHECK: %[[V_34:[0-9]+]] = arith.cmpi ne, %[[V_33]], %c0{{.*}} : 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>
94 ! CHECK: %[[V_37:[0-9]+]] = fir.call @_FortranAioBeginExternalListOutput
95 ! CHECK: %[[V_38:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
96 ! CHECK: %[[V_39:[0-9]+]] = fir.load %[[V_38]] : !fir.ptr<i64>
97 ! CHECK: %[[V_40:[0-9]+]] = 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
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>
108 ! CHECK: %[[V_18:[0-9]+]] = fir.zero_bits !fir.ptr<i64>
109 ! CHECK: fir.store %[[V_18]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
110 ! CHECK: %[[V_19:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
111 ! CHECK: fir.freemem %[[V_19]] : !fir.heap<i64>
112 ! CHECK: %[[V_20:[0-9]+]] = fir.zero_bits !fir.heap<i64>
113 ! CHECK: fir.store %[[V_20]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
114 ! CHECK: %[[V_21:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
115 ! CHECK: %[[V_22:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
116 ! CHECK: %[[V_23:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
117 ! CHECK: fir.if %[[V_23]] {
118 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCount(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
119 ! CHECK: fir.store %[[V_29]] to %arg0 : !fir.ref<i64>
121 ! CHECK: %[[V_24:[0-9]+]] = fir.convert %[[V_21]] : (!fir.ptr<i64>) -> i64
122 ! CHECK: %[[V_25:[0-9]+]] = arith.cmpi ne, %[[V_24]], %c0{{.*}} : i64
123 ! CHECK: fir.if %[[V_25]] {
124 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
125 ! CHECK: fir.store %[[V_29]] to %[[V_21]] : !fir.ptr<i64>
127 ! CHECK: %[[V_26:[0-9]+]] = fir.convert %[[V_22]] : (!fir.heap<i64>) -> i64
128 ! CHECK: %[[V_27:[0-9]+]] = arith.cmpi ne, %[[V_26]], %c0{{.*}} : i64
129 ! CHECK: fir.if %[[V_27]] {
130 ! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountMax(%c8{{.*}}_i32) {{.*}}: (i32) -> i64
131 ! CHECK: fir.store %[[V_29]] to %[[V_22]] : !fir.heap<i64>
133 ! CHECK: %[[V_28:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
134 ! CHECK: fir.if %[[V_28]] {
135 ! CHECK: %[[V_31]] = fir.call @_FortranAioBeginExternalListOutput
136 ! CHECK: %[[V_32]] = fir.load %arg0 : !fir.ref<i64>
137 ! CHECK: %[[V_33]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_32]]) {{.*}}: (!fir.ref<i8>, i64) -> i1
138 ! CHECK: %[[V_34]] = fir.call @_FortranAioEndIoStatement(%[[V_31]]) {{.*}}: (!fir.ref<i8>) -> i32
143 integer(8), optional
:: count
144 integer(8), target
:: count_rate_
145 integer(8), pointer :: count_rate
146 integer(8), allocatable
:: count_max
148 count_rate
=> count_rate_
150 call system_clock(count
, count_rate
, count_max
)
151 if (present(count
)) then
152 print*, count
, count_rate
, count_max
154 call system_clock(count_rate
=count_rate
, count_max
=count_max
)
155 print*, count_rate
, count_max
158 if (present(count
)) count
= 0
160 deallocate(count_max
)
161 call system_clock(count
, count_rate
, count_max
)
162 if (present(count
)) print*, count