Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5896,6 +5896,7 @@ def print_enabled_extensions : Flag<["-", "--"], "print-enabled-extensions">,
def : Flag<["-"], "mcpu=help">, Alias<print_supported_cpus>;
def : Flag<["-"], "mtune=help">, Alias<print_supported_cpus>;
def time : Flag<["-"], "time">,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is not expected to work on Windows, then should we have CLOption and DXCOption? Or are these just added for compatibility with the previous setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why it should not work on Windows. But there was a failing Windows buildkite, so I temporarily disabled the test. I will try again to see if it was a transient issue. If the issue still persists, I will add a comment indicating that the option should work on Windows, but that the original author did not have a means to test it and, therefore, disabled it. Since some of the tests require a full toolchain to be present, @MaskRay suggested being conservative about where the tests were run.

I have generally kept CLOption and DXCOption when the original did not explicitly specify anything for compatibility.

HelpText<"Time individual commands">;
def traditional_cpp : Flag<["-", "--"], "traditional-cpp">,
Visibility<[ClangOption, CC1Option]>,
Expand Down
20 changes: 20 additions & 0 deletions clang/lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
#include <cassert>
Expand Down Expand Up @@ -194,11 +197,28 @@ int Compilation::ExecuteCommand(const Command &C,
if (LogOnly)
return 0;

// We don't use any timers or llvm::TimeGroup's because those are tied into
// the global static timer list which, in principle, could be cleared without
// us knowing about it.
llvm::TimeRecord StartTime;
if (getArgs().hasArg(options::OPT_time))
StartTime = llvm::TimeRecord::getCurrentTime(/*Start=*/true);

std::string Error;
bool ExecutionFailed;
int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
if (PostCallback)
PostCallback(C, Res);

if (getArgs().hasArg(options::OPT_time)) {
llvm::TimeRecord Time = llvm::TimeRecord::getCurrentTime(/*Start=*/false);
Time -= StartTime;
llvm::StringRef Name = llvm::sys::path::filename(C.getExecutable());
llvm::errs() << "# " << Name << " "
<< llvm::format("%0.2f", Time.getUserTime()) << " "
<< llvm::format("%0.2f", Time.getSystemTime()) << "\n";
}

if (!Error.empty()) {
assert(Res && "Error string set with 0 result code!");
getDriver().Diag(diag::err_drv_command_failure) << Error;
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
// Ignore -pipe.
Args.ClaimAllArgs(options::OPT_pipe);

// Ignore -time.
Args.ClaimAllArgs(options::OPT_time);

// Extract -ccc args.
//
// FIXME: We need to figure out where this behavior should live. Most of it
Expand Down
33 changes: 33 additions & 0 deletions clang/test/Driver/time.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// The -time option prints timing information for the various subcommands in a
// format similar to that used by gcc. When compiling and linking, this will
// include the time to call clang-${LLVM_VERSION_MAJOR} and the linker. Since
// the name of the linker could vary across platforms, and name of the compiler
// could be something different, just check that whatever is printed to stderr
// looks like timing information.

// Ideally, this should be tested on various platforms, but that requires the
// the full toolchain, including a linker to be present. The initial author of
// the test only had access to Linux on x86 which is why this is only enabled
// there. More platforms ought to be added if possible.

// REQUIRES: x86-registered-target
// REQUIRES: x86_64-linux

// RUN: %clang --target=x86_64-pc-linux -time -c -o /dev/null %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
// RUN: %clang --target=x86_64-pc-linux -time -S -emit-llvm -o /dev/null %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
// RUN: %clang --target=x86_64-pc-linux -time -S -o /dev/null %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
// RUN: %clang --target=x86_64-pc-linux -time -o /dev/null %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=COMPILE-AND-LINK

// COMPILE-ONLY: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
// COMPILE-ONLY-NOT: {{.}}

// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
// COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}

int main() {
return 0;
}
36 changes: 36 additions & 0 deletions flang/test/Driver/time.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
! TODO: For some reason, on Windows, nothing is printed to stderr which causes
! the checks to fail. It is not clear why this is, so disable this on Windows
! until the root cause can be determined.
!
! UNSUPPORTED: system-windows

! The -time option prints timing information for the various subcommands in a
! format similar to that used by gfortran. When compiling and linking, this will
! include the time to call flang-${LLVM_VERSION_MAJOR} and the linker. Since the
! name of the linker could vary across platforms, and the flang name could also
! potentially be something different, just check that whatever is printed to
! stderr looks like timing information.

! Ideally, this should be tested on various platforms, but that requires the
! the full toolchain, including a linker to be present. The initial author of
! the test only had access to Linux on x86 which is why this is only enabled
! there. More platforms ought to be added if possible.

! REQUIRES: x86_64-linux

! RUN: %flang --target=x86_64-linux -time -c -o /dev/null %s 2>&1 \
! RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
! RUN: %flang --target=x86_64-linux -time -S -emit-llvm -O3 -o /dev/null %s 2>&1 \
! RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
! RUN: %flang --target=x86_64-linux -time -S -o /dev/null %s 2>&1 \
! RUN: | FileCheck %s --check-prefix=COMPILE-ONLY
! RUN: %flang --target=x86_64-linux -time -o /dev/null %s 2>&1 \
! RUN: | FileCheck %s --check-prefix=COMPILE-AND-LINK

! COMPILE-ONLY: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
! COMPILE-ONLY-NOT: {{.}}

! COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}
! COMPILE-AND-LINK: # {{.+}} {{[0-9]+(.[0-9]+)?}} {{[0-9]+(.[0-9]+)?}}

end program
Loading