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

Weiwei C via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 25 08:04:26 PDT 2026


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

>From 83d4e509a0cea8bffce3cc8512dc4f07fdd8c16f Mon Sep 17 00:00:00 2001
From: Weiwei Chen <weiwei.chen at modular.com>
Date: Mon, 24 Aug 2026 14:56:46 -0400
Subject: [PATCH] [llvm][timing] Reset recycled timer with different names.

---
 llvm/lib/IR/PassTimingInfo.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

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();
 }
 



More information about the llvm-commits mailing list