[libc++] Remove workarounds for the lack of clock_gettime on older macOS platforms

This increases the Mac OS requirement for building libc++ to 10.12.
Note that it doesn't change whether the *headers* still support older
platforms -- it's only that macOS >= 10.12 is required to build the
dylib from sources.

Differential Revision: https://reviews.llvm.org/D74489

Cr-Mirrored-From: https://chromium.googlesource.com/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: babd3aefc9193b44ad0620a2cfd63ebb6ad7e952
diff --git a/src/chrono.cpp b/src/chrono.cpp
index a1a456f..f0a5d50 100644
--- a/src/chrono.cpp
+++ b/src/chrono.cpp
@@ -9,7 +9,7 @@
 #include "chrono"
 #include "cerrno"        // errno
 #include "system_error"  // __throw_system_error
-#include <time.h>        // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
+#include <time.h>        // clock_gettime and CLOCK_{MONOTONIC,REALTIME,MONOTONIC_RAW}
 #include "include/apple_availability.h"
 
 #if __has_include(<unistd.h>)
@@ -21,28 +21,20 @@
 #endif
 
 #if defined(_LIBCPP_WIN32API)
-#define WIN32_LEAN_AND_MEAN
-#define VC_EXTRA_LEAN
-#include <windows.h>
-#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
-#include <winapifamily.h>
-#endif
+#  define WIN32_LEAN_AND_MEAN
+#  define VC_EXTRA_LEAN
+#  include <windows.h>
+#  if _WIN32_WINNT >= _WIN32_WINNT_WIN8
+#    include <winapifamily.h>
+#  endif
 #else
-#if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME)
-#include <sys/time.h> // for gettimeofday and timeval
-#endif
+#  if !defined(CLOCK_REALTIME)
+#    include <sys/time.h>        // for gettimeofday and timeval
+#  endif // !defined(CLOCK_REALTIME)
 #endif // defined(_LIBCPP_WIN32API)
 
-#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
-#if __APPLE__
-#include <mach/mach_time.h>  // mach_absolute_time, mach_timebase_info_data_t
-#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
-#error "Monotonic clock not implemented"
-#endif
-#endif
-
 #if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
-#pragma comment(lib, "rt")
+#  pragma comment(lib, "rt")
 #endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
@@ -82,7 +74,7 @@
                        static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast<duration>(d - nt_to_unix_epoch));
 #else
-#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
+#if defined(CLOCK_REALTIME)
   struct timespec tp;
   if (0 != clock_gettime(CLOCK_REALTIME, &tp))
     __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
@@ -91,7 +83,7 @@
     timeval tv;
     gettimeofday(&tv, 0);
     return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
-#endif // _LIBCPP_USE_CLOCK_GETTIME && CLOCK_REALTIME
+#endif // CLOCK_REALTIME
 #endif
 }
 
@@ -118,8 +110,15 @@
 
 #if defined(__APPLE__)
 
-// Darwin libc versions >= 1133 provide ns precision via CLOCK_MONOTONIC_RAW
-#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC_RAW)
+#if !defined(CLOCK_MONOTONIC_RAW)
+#  error "Building libc++ on Apple platforms requires CLOCK_MONOTONIC_RAW"
+#endif
+
+// On Apple platforms, only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or
+// mach_absolute_time are able to time functions in the nanosecond range.
+// Furthermore, only CLOCK_MONOTONIC_RAW is truly monotonic, because it
+// also counts cycles when the system is asleep. Thus, it is the only
+// acceptable implementation of steady_clock.
 steady_clock::time_point
 steady_clock::now() _NOEXCEPT
 {
@@ -129,60 +128,6 @@
     return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
 }
 
-#else
-//   mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
-//   nanoseconds since the computer booted up.  MachInfo.numer and MachInfo.denom
-//   are run time constants supplied by the OS.  This clock has no relationship
-//   to the Gregorian calendar.  It's main use is as a high resolution timer.
-
-// MachInfo.numer / MachInfo.denom is often 1 on the latest equipment.  Specialize
-//   for that case as an optimization.
-
-static
-steady_clock::rep
-steady_simplified()
-{
-    return static_cast<steady_clock::rep>(mach_absolute_time());
-}
-
-static
-double
-compute_steady_factor()
-{
-    mach_timebase_info_data_t MachInfo;
-    mach_timebase_info(&MachInfo);
-    return static_cast<double>(MachInfo.numer) / MachInfo.denom;
-}
-
-static
-steady_clock::rep
-steady_full()
-{
-    static const double factor = compute_steady_factor();
-    return static_cast<steady_clock::rep>(mach_absolute_time() * factor);
-}
-
-typedef steady_clock::rep (*FP)();
-
-static
-FP
-init_steady_clock()
-{
-    mach_timebase_info_data_t MachInfo;
-    mach_timebase_info(&MachInfo);
-    if (MachInfo.numer == MachInfo.denom)
-        return &steady_simplified;
-    return &steady_full;
-}
-
-steady_clock::time_point
-steady_clock::now() _NOEXCEPT
-{
-    static FP fp = init_steady_clock();
-    return time_point(duration(fp()));
-}
-#endif // defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC_RAW)
-
 #elif defined(_LIBCPP_WIN32API)
 
 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says:
@@ -210,13 +155,6 @@
 
 #elif defined(CLOCK_MONOTONIC)
 
-// On Apple platforms only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or
-// mach_absolute_time are able to time functions in the nanosecond range.
-// Thus, they are the only acceptable implementations of steady_clock.
-#ifdef __APPLE__
-#error "Never use CLOCK_MONOTONIC for steady_clock::now on Apple platforms"
-#endif
-
 steady_clock::time_point
 steady_clock::now() _NOEXCEPT
 {
@@ -227,7 +165,7 @@
 }
 
 #else
-#error "Monotonic clock not implemented"
+#  error "Monotonic clock not implemented"
 #endif
 
 #endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK