Skip to content

[clang][timers][stats] Add a flag to enable timers in the stats file #149946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2025
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
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ CODEGENOPT(SpeculativeLoadHardening, 1, 0, Benign) ///< Enable speculative load
CODEGENOPT(FineGrainedBitfieldAccesses, 1, 0, Benign) ///< Enable fine-grained bitfield accesses.
CODEGENOPT(StrictEnums , 1, 0, Benign) ///< Optimize based on strict enum definition.
CODEGENOPT(StrictVTablePointers, 1, 0, Benign) ///< Optimize based on the strict vtable pointers
CODEGENOPT(TimePasses , 1, 0, Benign) ///< Set when -ftime-report or -ftime-report= or -ftime-report-json is enabled.
CODEGENOPT(TimePasses , 1, 0, Benign) ///< Set when -ftime-report, -ftime-report=, -ftime-report-json, or -stats-file-timers is enabled.
CODEGENOPT(TimePassesPerRun , 1, 0, Benign) ///< Set when -ftime-report=per-pass-run is enabled.
CODEGENOPT(TimePassesJson , 1, 0, Benign) ///< Set when -ftime-report-json is enabled.
CODEGENOPT(TimePassesStatsFile , 1, 0, Benign) ///< Set when -stats-file-timers is enabled.
CODEGENOPT(TimeTrace , 1, 0, Benign) ///< Set when -ftime-trace is enabled.
VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500, Benign) ///< Minimum time granularity (in microseconds),
///< traced by time profiler
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8253,6 +8253,9 @@ def stats_file : Joined<["-"], "stats-file=">,
def stats_file_append : Flag<["-"], "stats-file-append">,
HelpText<"If stats should be appended to stats-file instead of overwriting it">,
MarshallingInfoFlag<FrontendOpts<"AppendStats">>;
def stats_file_timers : Flag<["-"], "stats-file-timers">,
HelpText<"If stats should include timers.">,
MarshallingInfoFlag<CodeGenOpts<"TimePassesStatsFile">>;
def fdump_record_layouts_simple : Flag<["-"], "fdump-record-layouts-simple">,
HelpText<"Dump record layout information in a simple form used for testing">,
MarshallingInfoFlag<LangOpts<"DumpRecordLayoutsSimple">>;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,8 +2013,8 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
: llvm::codegenoptions::DebugTemplateNamesKind::Mangled);
}

if (const Arg *A = Args.getLastArg(OPT_ftime_report, OPT_ftime_report_EQ,
OPT_ftime_report_json)) {
if (Args.hasArg(OPT_ftime_report, OPT_ftime_report_EQ, OPT_ftime_report_json,
OPT_stats_file_timers)) {
Opts.TimePasses = true;

// -ftime-report= is only for new pass manager.
Expand All @@ -2026,7 +2026,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
Opts.TimePassesPerRun = true;
else
Diags.Report(diag::err_drv_invalid_value)
<< A->getAsString(Args) << A->getValue();
<< EQ->getAsString(Args) << EQ->getValue();
}

if (Args.getLastArg(OPT_ftime_report_json))
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Misc/time-passes.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
// RUN: -ftime-report-json %s -o /dev/null \
// RUN: -mllvm -info-output-file=%t
// RUN: cat %t | FileCheck %s --check-prefixes=JSON
// Check that -stats-file-timers only outputs pass time info in the stats file
// and not stderr.
// RUN: %clang_cc1 -emit-obj -O1 \
// RUN: %s -o /dev/null \
// RUN: -stats-file=%t -stats-file-timers 2>&1 | count 0
// RUN: FileCheck %s -input-file=%t -check-prefixes=JSON

// TIME: Pass execution timing report
// TIME: Total Execution Time:
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/driver/cc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
*IOFile << "{\n";
llvm::TimerGroup::printAllJSONValues(*IOFile, "");
*IOFile << "\n}\n";
} else {
} else if (!Clang->getCodeGenOpts().TimePassesStatsFile) {
llvm::TimerGroup::printAll(*IOFile);
}
llvm::TimerGroup::clearAll();
Expand Down