[llvm] 5db95fd - [memprof] Avoid repeated hash lookups (NFC) (#136268)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 18 01:07:08 PDT 2025


Author: Kazu Hirata
Date: 2025-04-18T01:07:05-07:00
New Revision: 5db95fd6ca8cae62c6ab6acf17b00c3417d2018d

URL: https://github.com/llvm/llvm-project/commit/5db95fd6ca8cae62c6ab6acf17b00c3417d2018d
DIFF: https://github.com/llvm/llvm-project/commit/5db95fd6ca8cae62c6ab6acf17b00c3417d2018d.diff

LOG: [memprof] Avoid repeated hash lookups (NFC) (#136268)

Note that we don't have to worry about CallstackProfileData[Id]
default-constructing the value side of a new map entry.  If that
happens, AccessHistogramSize > 0 wouldn't be true, and the new map
entry gets deleted right away.

Added: 
    

Modified: 
    llvm/lib/ProfileData/MemProfReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index c57f9b22273d4..e0f280b9eb2f6 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -600,9 +600,12 @@ Error RawMemProfReader::symbolizeAndFilterStackFrames(
   // Drop the entries where the callstack is empty.
   for (const uint64_t Id : EntriesToErase) {
     StackMap.erase(Id);
-    if (CallstackProfileData[Id].AccessHistogramSize > 0)
-      free((void *)CallstackProfileData[Id].AccessHistogram);
-    CallstackProfileData.erase(Id);
+    if (auto It = CallstackProfileData.find(Id);
+        It != CallstackProfileData.end()) {
+      if (It->second.AccessHistogramSize > 0)
+        free((void *)It->second.AccessHistogram);
+      CallstackProfileData.erase(It);
+    }
   }
 
   if (StackMap.empty())


        


More information about the llvm-commits mailing list