[clang] [llvm] [Timer] Use unique keys for JSON output for -ftime-report=per-pass-run (PR #248299)

via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 4 17:02:11 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Arthur Eubanks (aeubanks)

<details>
<summary>Changes</summary>

-ftime-report=per-pass-run is supposed to display separate pass invocations as separate entries. But in the JSON we'd put them all as the same key (e.g. "InstCombine").

Now we output a key like "InstCombine_1" to distinguish separate pass invocations.

Assisted by Gemini

---
Full diff: https://github.com/llvm/llvm-project/pull/248299.diff


2 Files Affected:

- (modified) clang/test/Misc/time-passes.c (+9) 
- (modified) llvm/lib/IR/PassTimingInfo.cpp (+2-1) 


``````````diff
diff --git a/clang/test/Misc/time-passes.c b/clang/test/Misc/time-passes.c
index 6afbcd466378dd..d99177190300c9 100644
--- a/clang/test/Misc/time-passes.c
+++ b/clang/test/Misc/time-passes.c
@@ -16,6 +16,9 @@
 // RUN:     -ftime-report-json %s -o /dev/null 2>&1 | \
 // RUN:     FileCheck %s --check-prefixes=JSON
 // RUN: %clang_cc1 -emit-obj -O1 \
+// RUN:     -ftime-report=per-pass-run -ftime-report-json %s -o /dev/null 2>&1 | \
+// RUN:     FileCheck %s --check-prefixes=JSON-PER-INVOKE
+// RUN: %clang_cc1 -emit-obj -O1 \
 // RUN:     -ftime-report-json %s -o /dev/null \
 // RUN:     -mllvm -info-output-file=%t
 // RUN: cat %t | FileCheck %s --check-prefixes=JSON
@@ -41,5 +44,11 @@
 // JSON: "time.pass.InstCombinePass.user": {{.*}},
 // JSON: "time.pass.InstCombinePass.sys": {{.*}},
 // JSON:}
+// JSON-PER-INVOKE:{
+// JSON-PER-INVOKE-NOT: "time.pass.InstCombinePass.wall":
+// JSON-PER-INVOKE-DAG: "time.pass.InstCombinePass_1.wall": {{.*}},
+// JSON-PER-INVOKE-DAG: "time.pass.InstCombinePass_2.wall": {{.*}},
+// JSON-PER-INVOKE-DAG: "time.pass.InstCombinePass_3.wall": {{.*}},
+// JSON-PER-INVOKE:}
 
 int foo(int x, int y) { return x + y; }
diff --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp
index 3c5b85d3d691e0..90899a410331f4 100644
--- a/llvm/lib/IR/PassTimingInfo.cpp
+++ b/llvm/lib/IR/PassTimingInfo.cpp
@@ -179,9 +179,10 @@ Timer &TimePassesHandler::getPassTimer(StringRef PassID, bool IsPass) {
   TimerVector &Timers = TimingData[PassID];
   unsigned Count = Timers.size() + 1;
 
+  std::string FullName = formatv("{0}_{1}", PassID, Count).str();
   std::string FullDesc = formatv("{0} #{1}", PassID, Count).str();
 
-  Timer *T = new Timer(PassID, FullDesc, TG);
+  Timer *T = new Timer(FullName, FullDesc, TG);
   Timers.emplace_back(T);
   assert(Count == Timers.size() && "Timers vector not adjusted correctly.");
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/248299


More information about the cfe-commits mailing list