Greetings,
I’ve tried implementing a Ftime-Report Option and it gives me clang: warning: argument unused during compilation: ‘-ftime-report-detailed’ [-Wunused-command-line-argument]
The Timer logic should be fine afterwards but there seems to be a very subtle issue with this code, Not sure if I’m injecting it correctly or CC1 is complaining here but seems right to me.
From 60aa318de0139baf090ad5509f25a0e7b4f38415 Mon Sep 17 00:00:00 2001
From: Nicholas Krause <xerofoify@gmail.com>
Date: Thu, 22 May 2025 02:05:57 -0400
Subject: [PATCH] Test
Signed-off-by: Nicholas Krause <xerofoify@gmail.com>
---
clang/include/clang/Basic/CodeGenOptions.def | 1 +
clang/include/clang/Driver/Options.td | 4 ++++
clang/lib/CodeGen/BackendUtil.cpp | 5 ++++-
clang/lib/Frontend/CompilerInvocation.cpp | 8 +++++++-
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index aad4e107cbeb..54daab38f2bd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -320,6 +320,7 @@ CODEGENOPT(FineGrainedBitfieldAccesses, 1, 0) ///< Enable fine-grained bitfield
CODEGENOPT(StrictEnums , 1, 0) ///< Optimize based on strict enum definition.
CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict vtable pointers
CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report or -ftime-report= or -ftime-report-json is enabled.
+CODEGENOPT(TimePassesDetailed, 1, 0) ///< Set when -ftime-report-detailed is enabled.
CODEGENOPT(TimePassesPerRun , 1, 0) ///< Set when -ftime-report=per-pass-run is enabled.
CODEGENOPT(TimePassesJson , 1, 0) ///< Set when -ftime-report-json is enabled.
CODEGENOPT(TimeTrace , 1, 0) ///< Set when -ftime-trace is enabled.
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 9a4253113488..49982605fa51 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4134,6 +4134,10 @@ defm ms_tls_guards : BoolFOption<"ms-tls-guards",
def ftime_report : Flag<["-"], "ftime-report">, Group<f_Group>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
MarshallingInfoFlag<CodeGenOpts<"TimePasses">>;
+def ftime_report_detailed : Flag<["-"], "ftime-report-detailed">,
+ HelpText<"Enable detailed time report for code generation passes with function context">,
+ Visibility<[ClangOption, CC1Option]>,
+ MarshallingInfoFlag<CodeGenOpts<"TimePassesDetailed">>;
def ftime_report_json
: Flag<["-"], "ftime-report-json">,
Group<f_Group>,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 42c59377688b..092d3d1803fc 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -924,6 +924,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
TheModule->getContext(),
(CodeGenOpts.DebugPassManager || DebugPassStructure),
CodeGenOpts.VerifyEach, PrintPassOpts);
+ if (CodeGenOpts.TimePassesDetailed) {
+ llvm::setTimePassesDetailedEnabled(true); // Enable detailed reporting
+ }
SI.registerCallbacks(PIC, &MAM);
PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
@@ -1141,7 +1144,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
// requires code generation because there will already be a verifier pass in
// the code-generation pipeline.
// Since we already added a verifier pass above, this
- // might even not run the analysis, if previous passes caused no changes.
+ // might even not uun the analysis, if previous passes caused no changes.
if (!actionRequiresCodeGen(Action) && CodeGenOpts.VerifyModule)
MPM.addPass(VerifierPass());
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 3c23073fc6a8..4cf45ad84036 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2023,8 +2023,14 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
<< A->getAsString(Args) << A->getValue();
}
- if (Args.getLastArg(OPT_ftime_report_json))
+ // Parse -ftime-report-detailed
+ if (Args.getLastArg(OPT_ftime_report_detailed))
+ CodeGenOpts.TimePassesDetailed = true; // Enable detailed time reporting
+
+ if (Args.getLastArg(OPT_ftime_report_json))
Opts.TimePassesJson = true;
+
+
}
Opts.PrepareForLTO = false;
--
2.49.0