Skip to content

Commit 75ba7f3

Browse files
committed
Revert "[flang] Add default implementation for SYSTEM_CLOCK"
This reverts commit c4454f0.
1 parent 66af69c commit 75ba7f3

File tree

2 files changed

+0
-80
lines changed

2 files changed

+0
-80
lines changed

flang/runtime/time-intrinsic.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <ctime>
1414

1515
// CPU_TIME (Fortran 2018 16.9.57)
16-
// SYSTEM_CLOCK (Fortran 2018 16.9.168)
17-
//
1816
// We can use std::clock() from the <ctime> header as a fallback implementation
1917
// that should be available everywhere. This may not provide the best resolution
2018
// and is particularly troublesome on (some?) POSIX systems where CLOCKS_PER_SEC
@@ -70,59 +68,11 @@ double GetCpuTime(preferred_implementation,
7068
// Return some negative value to represent failure.
7169
return -1.0;
7270
}
73-
74-
using count_t =
75-
Fortran::runtime::CppTypeFor<Fortran::common::TypeCategory::Integer, 8>;
76-
77-
// This is the fallback implementation, which should work everywhere. Note that
78-
// in general we can't recover after std::clock has reached its maximum value.
79-
template <typename Unused = void>
80-
count_t GetSystemClockCount(fallback_implementation) {
81-
std::clock_t timestamp{std::clock()};
82-
if (timestamp == static_cast<std::clock_t>(-1)) {
83-
// Return -HUGE() to represent failure.
84-
return -std::numeric_limits<count_t>::max();
85-
}
86-
87-
// If our return type is large enough to hold any value returned by
88-
// std::clock, our work is done. Otherwise, we have to wrap around.
89-
static constexpr auto max{std::numeric_limits<count_t>::max()};
90-
if constexpr (max <= std::numeric_limits<count_t>::max()) {
91-
return static_cast<count_t>(timestamp);
92-
} else {
93-
// Since std::clock_t could be a floating point type, we can't just use the
94-
// % operator, so we have to wrap around manually.
95-
return static_cast<count_t>(timestamp - max * std::floor(timestamp / max));
96-
}
97-
}
98-
99-
template <typename Unused = void>
100-
count_t GetSystemClockCountRate(fallback_implementation) {
101-
return CLOCKS_PER_SEC;
102-
}
103-
104-
template <typename Unused = void>
105-
count_t GetSystemClockCountMax(fallback_implementation) {
106-
return std::min(std::numeric_limits<std::clock_t>::max(),
107-
std::numeric_limits<count_t>::max());
108-
}
10971
} // anonymous namespace
11072

11173
namespace Fortran::runtime {
11274
extern "C" {
11375

11476
double RTNAME(CpuTime)() { return GetCpuTime(0); }
115-
116-
CppTypeFor<TypeCategory::Integer, 8> RTNAME(SystemClockCount)() {
117-
return GetSystemClockCount(0);
118-
}
119-
120-
CppTypeFor<TypeCategory::Integer, 8> RTNAME(SystemClockCountRate)() {
121-
return GetSystemClockCountRate(0);
122-
}
123-
124-
CppTypeFor<TypeCategory::Integer, 8> RTNAME(SystemClockCountMax)() {
125-
return GetSystemClockCountMax(0);
126-
}
12777
} // extern "C"
12878
} // namespace Fortran::runtime

flang/unittests/RuntimeGTest/Time.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,3 @@ TEST(TimeIntrinsics, CpuTime) {
2626
ASSERT_GE(end, start);
2727
}
2828
}
29-
30-
using count_t = CppTypeFor<TypeCategory::Integer, 8>;
31-
32-
TEST(TimeIntrinsics, SystemClock) {
33-
// We can't really test that we get the "right" result for SYSTEM_CLOCK, but
34-
// we can have a smoke test to see that we get something reasonable on the
35-
// platforms where we expect to support it.
36-
37-
// The value of the count rate and max will vary by platform, but they should
38-
// always be strictly positive if we have a working implementation of
39-
// SYSTEM_CLOCK.
40-
EXPECT_GT(RTNAME(SystemClockCountRate)(), 0);
41-
42-
count_t max{RTNAME(SystemClockCountMax)()};
43-
EXPECT_GT(max, 0);
44-
45-
count_t start{RTNAME(SystemClockCount)()};
46-
EXPECT_GE(start, 0);
47-
EXPECT_LE(start, max);
48-
49-
// Loop until we get a different value from SystemClockCount. If we don't get
50-
// one before we time out, then we should probably look into an implementation
51-
// for SystemClokcCount with a better timer resolution on this platform.
52-
for (count_t end = start; end == start; end = RTNAME(SystemClockCount)()) {
53-
EXPECT_GE(end, 0);
54-
EXPECT_LE(end, max);
55-
56-
EXPECT_GE(end, start);
57-
}
58-
}

0 commit comments

Comments
 (0)