[llvm] [memprof] Avoid repeated hash lookups (NFC) (PR #136268)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 17 23:39:27 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

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.


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


1 Files Affected:

- (modified) llvm/lib/ProfileData/MemProfReader.cpp (+6-3) 


``````````diff
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())

``````````

</details>


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


More information about the llvm-commits mailing list