[llvm] [llvm][timing] Reset recycled timer with different names. (PR #218492)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 11:59:50 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Weiwei C (weiweichen)

<details>
<summary>Changes</summary>

Legacy pass-manager timers are keyed by the pass instance pointer and the map entry outlives the pass, so a pass allocated at a recycled address inherits the previous pass's timer and reports its time under that pass's name. When a recycled instance which has different name can end up having leftover name comes from whichever target ran before. Re-create the timer when the name no longer matches.

fixes: #<!-- -->218491 

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


1 Files Affected:

- (modified) llvm/lib/IR/PassTimingInfo.cpp (+13-7) 


``````````diff
diff --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp
index 487cef0bce12a..3c5b85d3d691e 100644
--- a/llvm/lib/IR/PassTimingInfo.cpp
+++ b/llvm/lib/IR/PassTimingInfo.cpp
@@ -123,15 +123,21 @@ Timer *PassTimingInfo::getPassTimer(Pass *P, PassInstanceID Pass) {
 
   init();
   sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
+  StringRef PassName = P->getPassName();
+  StringRef PassArgument;
+  if (const PassInfo *PI = Pass::lookupPassInfo(P->getPassID()))
+    PassArgument = PI->getPassArgument();
+  StringRef TimerName = PassArgument.empty() ? PassName : PassArgument;
+
   std::unique_ptr<Timer> &T = TimingData[Pass];
 
-  if (!T) {
-    StringRef PassName = P->getPassName();
-    StringRef PassArgument;
-    if (const PassInfo *PI = Pass::lookupPassInfo(P->getPassID()))
-      PassArgument = PI->getPassArgument();
-    T.reset(newPassTimer(PassArgument.empty() ? PassName : PassArgument, PassName));
-  }
+  // This map outlives the pass instances it is keyed on, so a new pass can be
+  // allocated at a destroyed one's address. Its timer carries the old name.
+  if (T && T->getName() != TimerName)
+    T.reset();
+
+  if (!T)
+    T.reset(newPassTimer(TimerName, PassName));
   return T.get();
 }
 

``````````

</details>


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


More information about the llvm-commits mailing list