[flang] Add default implementation for SYSTEM_CLOCK
authorDiana Picus <diana.picus@linaro.org>
Mon, 12 Jul 2021 13:45:44 +0000 (13:45 +0000)
committerDiana Picus <diana.picus@linaro.org>
Wed, 18 Aug 2021 07:39:13 +0000 (07:39 +0000)
commit0104cc85b14aad7980360f58a1159463f8da5adb
tree1a28fce483814d12ff906edb16b324f856dbd5d2
parent284006079e0e2db986d1cacce8cb5329ffb86044
[flang] Add default implementation for SYSTEM_CLOCK

Add an implementation for the runtime functions related to SYSTEM_CLOCK.
As with CPU_TIME, this is based on std::clock(), which should be
available everywhere, but it is highly recommended to add
platform-specific implementations for systems where std::clock() behaves
poorly (e.g. POSIX).

The documentation for std::clock() doesn't specify a maximum value and
in fact wrap around behaviour is non-conforming.  Therefore, this
implementation of SYSTEM_CLOCK is not guaranteed to wrap around either,
and after std::clock reaches its maximum value we will likely just
return failure rather than wrap around. If this happens often on your
system, please add a new platform-specific implementation.

We define COUNT_MAX as either the maximum value that can be stored in
a std::clock_t or in a 64-bit integer (whichever is smaller), and
COUNT_RATE as CLOCKS_PER_SEC. For POSIX systems, the value of
CLOCKS_PER_SEC is hardcoded to 10^6 and irrelevant for the values
returned by std::clock.

Differential Revision: https://reviews.llvm.org/D105969
flang/runtime/time-intrinsic.cpp
flang/unittests/Runtime/Time.cpp