[all-commits] [llvm/llvm-project] 166192: [flang] Add POSIX implementation for CPU_TIME

Diana via All-commits all-commits at lists.llvm.org
Mon Jun 14 02:42:32 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 166192eb78cdeb41ee25a37e920259fb13f82f6a
      https://github.com/llvm/llvm-project/commit/166192eb78cdeb41ee25a37e920259fb13f82f6a
  Author: Diana Picus <diana.picus at linaro.org>
  Date:   2021-06-14 (Mon, 14 Jun 2021)

  Changed paths:
    M flang/runtime/time-intrinsic.cpp

  Log Message:
  -----------
  [flang] Add POSIX implementation for CPU_TIME

Add an implementation for CPU_TIME using the POSIX function
clock_gettime. I think on most POSIX systems this will be included for
free via <ctime>, which corresponds to "time.h" (YMMV, we can fix the
code if the need arises).

Detecting that clock_gettime is available is tricky. For instance, commit
827407a86aa07 used the following incantation in f18-parse-demo.cpp:

  #if _POSIX_C_SOURCE >= 199309L && _POSIX_TIMERS > 0 && _POSIX_CPUTIME && \
    defined CLOCK_PROCESS_CPUTIME_ID

This doesn't work on my AArch64 Ubuntu system, which provides
clock_gettime but doesn't define _POSIX_TIMERS. Since finding the right
combination of macros requires infinite time, patience and access to
sundry POSIX systems, we should probably try a different approach.

This patch attempts to use SFINAE instead of the preprocessor to choose
an implementation for CPU_TIME. We define a helper function template
which helps us check if clock_gettime is available (and has the
interface we expect). I hope the comments explain it well enough.

This approach has the advantage that it keeps the detection of
clock_gettime close to the code that uses it. An alternative would be to
use CMake to check for the symbol (I personally haven't used this before
so I don't know if there are any quirks).

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




More information about the All-commits mailing list