diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Support/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/lib/Support/Chrono.cpp | 47 | ||||
| -rw-r--r-- | llvm/lib/Support/TimeValue.cpp | 17 | ||||
| -rw-r--r-- | llvm/lib/Support/Unix/TimeValue.inc | 54 | ||||
| -rw-r--r-- | llvm/lib/Support/Windows/TimeValue.inc | 61 |
5 files changed, 124 insertions, 56 deletions
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index d8ecfa9b862..cf04016da2d 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -37,7 +37,6 @@ add_llvm_library(LLVMSupport BranchProbability.cpp CachePruning.cpp circular_raw_ostream.cpp - Chrono.cpp COM.cpp CommandLine.cpp Compression.cpp diff --git a/llvm/lib/Support/Chrono.cpp b/llvm/lib/Support/Chrono.cpp deleted file mode 100644 index f0673be97f6..00000000000 --- a/llvm/lib/Support/Chrono.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===- Support/Chrono.cpp - Utilities for Timing Manipulation ---*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/Chrono.h" -#include "llvm/Config/config.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/raw_ostream.h" - -namespace llvm { - -using namespace sys; - -static inline struct tm getStructTM(TimePoint<> TP) { - struct tm Storage; - std::time_t OurTime = toTimeT(TP); - -#if defined(LLVM_ON_UNIX) - struct tm *LT = ::localtime_r(&OurTime, &Storage); - assert(LT); - (void)LT; -#endif -#if defined(LLVM_ON_WIN32) - int Error = ::_localtime64_s(&Storage, &OurTime); - assert(!Error); - (void)Error; -#endif - - return Storage; -} - -raw_ostream &operator<<(raw_ostream &OS, TimePoint<> TP) { - struct tm LT = getStructTM(TP); - char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")]; - strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", <); - return OS << Buffer << '.' - << format("%.9lu", - long((TP.time_since_epoch() % std::chrono::seconds(1)) - .count())); -} - -} // namespace llvm diff --git a/llvm/lib/Support/TimeValue.cpp b/llvm/lib/Support/TimeValue.cpp index 18c84ca9fa0..94a4c011693 100644 --- a/llvm/lib/Support/TimeValue.cpp +++ b/llvm/lib/Support/TimeValue.cpp @@ -12,8 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/TimeValue.h" -#include "llvm/Support/Chrono.h" -#include "llvm/Support/ScopedPrinter.h" +#include "llvm/Config/config.h" namespace llvm { @@ -46,10 +45,12 @@ void TimeValue::normalize() { } } -std::string TimeValue::str() const { return to_string(TimePoint<>(*this)); } - -TimeValue TimeValue::now() { - return TimePoint<>(std::chrono::system_clock::now()); -} - } // namespace llvm + +/// Include the platform-specific portion of TimeValue class +#ifdef LLVM_ON_UNIX +#include "Unix/TimeValue.inc" +#endif +#ifdef LLVM_ON_WIN32 +#include "Windows/TimeValue.inc" +#endif diff --git a/llvm/lib/Support/Unix/TimeValue.inc b/llvm/lib/Support/Unix/TimeValue.inc new file mode 100644 index 00000000000..042e0dacc34 --- /dev/null +++ b/llvm/lib/Support/Unix/TimeValue.inc @@ -0,0 +1,54 @@ +//===- Unix/TimeValue.cpp - Unix TimeValue Implementation -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the Unix specific portion of the TimeValue class. +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only generic UNIX code that +//=== is guaranteed to work on *all* UNIX variants. +//===----------------------------------------------------------------------===// + +#include "Unix.h" + +namespace llvm { + using namespace sys; + +std::string TimeValue::str() const { + time_t OurTime = time_t(this->toEpochTime()); + struct tm Storage; + struct tm *LT = ::localtime_r(&OurTime, &Storage); + assert(LT); + char Buffer1[sizeof("YYYY-MM-DD HH:MM:SS")]; + strftime(Buffer1, sizeof(Buffer1), "%Y-%m-%d %H:%M:%S", LT); + char Buffer2[sizeof("YYYY-MM-DD HH:MM:SS.MMMUUUNNN")]; + snprintf(Buffer2, sizeof(Buffer2), "%s.%.9u", Buffer1, this->nanoseconds()); + return std::string(Buffer2); +} + +TimeValue TimeValue::now() { + struct timeval the_time; + timerclear(&the_time); + if (0 != ::gettimeofday(&the_time,nullptr)) { + // This is *really* unlikely to occur because the only gettimeofday + // errors concern the timezone parameter which we're passing in as 0. + // In the unlikely case it does happen, just return MinTime, no error + // message needed. + return MinTime(); + } + + return TimeValue( + static_cast<TimeValue::SecondsType>( the_time.tv_sec + + PosixZeroTimeSeconds ), + static_cast<TimeValue::NanoSecondsType>( the_time.tv_usec * + NANOSECONDS_PER_MICROSECOND ) ); +} + +} diff --git a/llvm/lib/Support/Windows/TimeValue.inc b/llvm/lib/Support/Windows/TimeValue.inc new file mode 100644 index 00000000000..b90b4f1da00 --- /dev/null +++ b/llvm/lib/Support/Windows/TimeValue.inc @@ -0,0 +1,61 @@ +//===- Win32/TimeValue.cpp - Win32 TimeValue Implementation -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Win32 implementation of the TimeValue class. +// +//===----------------------------------------------------------------------===// + +#include "WindowsSupport.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" +#include <cctype> +#include <time.h> + +using namespace llvm; +using namespace llvm::sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Win32 specific code. +//===----------------------------------------------------------------------===// + +TimeValue TimeValue::now() { + uint64_t ft; + GetSystemTimeAsFileTime(reinterpret_cast<FILETIME *>(&ft)); + + TimeValue t(0, 0); + t.fromWin32Time(ft); + return t; +} + +std::string TimeValue::str() const { + std::string S; + struct tm *LT; +#ifdef __MINGW32__ + // Old versions of mingw don't have _localtime64_s. Remove this once we drop support + // for them. + time_t OurTime = time_t(this->toEpochTime()); + LT = ::localtime(&OurTime); + assert(LT); +#else + struct tm Storage; + __time64_t OurTime = this->toEpochTime(); + int Error = ::_localtime64_s(&Storage, &OurTime); + assert(!Error); + (void)Error; + LT = &Storage; +#endif + + char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")]; + strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", LT); + raw_string_ostream OS(S); + OS << format("%s.%.9u", static_cast<const char *>(Buffer), + this->nanoseconds()); + OS.flush(); + return S; +} |

