Skip to content

Commit ceeb20e

Browse files
committed
Merge commit '4a6c81dc0e27' from llvm.org/main into next
2 parents 6119ae6 + 4a6c81d commit ceeb20e

File tree

8 files changed

+35
-14
lines changed

8 files changed

+35
-14
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ New Compiler Flags
261261
The feature has `existed <https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#running-the-instrumented-program>`_)
262262
for a while and this is just a user facing option.
263263

264+
- New option ``-ftime-report-json`` added which outputs the same timing data as `-ftime-report` but formatted as JSON.
265+
264266
Deprecated Compiler Flags
265267
-------------------------
266268

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ CODEGENOPT(SpeculativeLoadHardening, 1, 0) ///< Enable speculative load hardenin
319319
CODEGENOPT(FineGrainedBitfieldAccesses, 1, 0) ///< Enable fine-grained bitfield accesses.
320320
CODEGENOPT(StrictEnums , 1, 0) ///< Optimize based on strict enum definition.
321321
CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict vtable pointers
322-
CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report or -ftime-report= is enabled.
322+
CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report or -ftime-report= or -ftime-report-json is enabled.
323323
CODEGENOPT(TimePassesPerRun , 1, 0) ///< Set when -ftime-report=per-pass-run is enabled.
324+
CODEGENOPT(TimePassesJson , 1, 0) ///< Set when -ftime-report-json is enabled.
324325
CODEGENOPT(TimeTrace , 1, 0) ///< Set when -ftime-trace is enabled.
325326
VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< Minimum time granularity (in microseconds),
326327
///< traced by time profiler

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,6 +4191,11 @@ defm ms_tls_guards : BoolFOption<"ms-tls-guards",
41914191
def ftime_report : Flag<["-"], "ftime-report">, Group<f_Group>,
41924192
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
41934193
MarshallingInfoFlag<CodeGenOpts<"TimePasses">>;
4194+
def ftime_report_json
4195+
: Flag<["-"], "ftime-report-json">,
4196+
Group<f_Group>,
4197+
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
4198+
MarshallingInfoFlag<CodeGenOpts<"TimePassesJson">>;
41944199
def ftime_report_EQ: Joined<["-"], "ftime-report=">, Group<f_Group>,
41954200
Visibility<[ClangOption, CC1Option]>, Values<"per-pass,per-pass-run">,
41964201
MarshallingInfoFlag<CodeGenOpts<"TimePassesPerRun">>,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7201,6 +7201,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job,
72017201
Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
72027202
Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
72037203
Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
7204+
Args.AddLastArg(CmdArgs, options::OPT_ftime_report_json);
72047205
Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
72057206
Args.AddLastArg(CmdArgs, options::OPT_malign_double);
72067207
Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,9 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts,
18951895
GenerateArg(Consumer, OPT_ftime_report_EQ, "per-pass-run");
18961896
else
18971897
GenerateArg(Consumer, OPT_ftime_report);
1898+
1899+
if (Opts.TimePassesJson)
1900+
GenerateArg(Consumer, OPT_ftime_report_json);
18981901
}
18991902

19001903
if (Opts.PrepareForLTO && !Opts.PrepareForThinLTO)
@@ -2203,17 +2206,13 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
22032206
: llvm::codegenoptions::DebugTemplateNamesKind::Mangled);
22042207
}
22052208

2206-
if (!Opts.ProfileInstrumentUsePath.empty()) {
2207-
auto FS = createBaseFS(FSOpts, FEOpts, CASOpts, Diags, nullptr);
2208-
setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath, *FS, Diags);
2209-
}
2210-
2211-
if (const Arg *A = Args.getLastArg(OPT_ftime_report, OPT_ftime_report_EQ)) {
2209+
if (const Arg *A = Args.getLastArg(OPT_ftime_report, OPT_ftime_report_EQ,
2210+
OPT_ftime_report_json)) {
22122211
Opts.TimePasses = true;
22132212

22142213
// -ftime-report= is only for new pass manager.
2215-
if (A->getOption().getID() == OPT_ftime_report_EQ) {
2216-
StringRef Val = A->getValue();
2214+
if (const Arg *EQ = Args.getLastArg(OPT_ftime_report_EQ)) {
2215+
StringRef Val = EQ->getValue();
22172216
if (Val == "per-pass")
22182217
Opts.TimePassesPerRun = false;
22192218
else if (Val == "per-pass-run")
@@ -2222,6 +2221,9 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
22222221
Diags.Report(diag::err_drv_invalid_value)
22232222
<< A->getAsString(Args) << A->getValue();
22242223
}
2224+
2225+
if (Args.getLastArg(OPT_ftime_report_json))
2226+
Opts.TimePassesJson = true;
22252227
}
22262228

22272229
Opts.PrepareForLTO = false;

clang/test/Misc/time-passes.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// RUN: %clang_cc1 -emit-obj -O1 \
99
// RUN: -ftime-report=per-pass-run %s -o /dev/null 2>&1 | \
1010
// RUN: FileCheck %s --check-prefixes=TIME,NPM-PER-INVOKE
11+
// RUN: %clang_cc1 -emit-obj -O1 \
12+
// RUN: -ftime-report-json %s -o /dev/null 2>&1 | \
13+
// RUN: FileCheck %s --check-prefixes=JSON
1114

1215
// TIME: Pass execution timing report
1316
// TIME: Total Execution Time:
@@ -19,5 +22,10 @@
1922
// NPM: InstCombinePass{{$}}
2023
// NPM-NOT: InstCombinePass #
2124
// TIME: Total{{$}}
25+
// JSON:{
26+
// JSON: "time.pass.InstCombinePass.wall": {{.*}},
27+
// JSON: "time.pass.InstCombinePass.user": {{.*}},
28+
// JSON: "time.pass.InstCombinePass.sys": {{.*}},
29+
// JSON:}
2230

2331
int foo(int x, int y) { return x + y; }

clang/tools/driver/cc1_main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,13 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
324324

325325
// If any timers were active but haven't been destroyed yet, print their
326326
// results now. This happens in -disable-free mode.
327-
llvm::TimerGroup::printAll(llvm::errs());
327+
if (Clang->getCodeGenOpts().TimePassesJson) {
328+
llvm::errs() << "{\n";
329+
llvm::TimerGroup::printAllJSONValues(llvm::errs(), "");
330+
llvm::errs() << "\n}\n";
331+
} else {
332+
llvm::TimerGroup::printAll(llvm::errs());
333+
}
328334
llvm::TimerGroup::clearAll();
329335

330336
if (llvm::timeTraceProfilerEnabled()) {

llvm/lib/Support/Timer.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,6 @@ void TimerGroup::clearAll() {
442442

443443
void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
444444
const char *suffix, double Value) {
445-
assert(yaml::needsQuotes(Name) == yaml::QuotingType::None &&
446-
"TimerGroup name should not need quotes");
447-
assert(yaml::needsQuotes(R.Name) == yaml::QuotingType::None &&
448-
"Timer name should not need quotes");
449445
constexpr auto max_digits10 = std::numeric_limits<double>::max_digits10;
450446
OS << "\t\"time." << Name << '.' << R.Name << suffix
451447
<< "\": " << format("%.*e", max_digits10 - 1, Value);

0 commit comments

Comments
 (0)