[llvm] [MemProf] Select largest of matching contexts from profile (PR #165338)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 30 19:05:47 PDT 2025


================
@@ -406,22 +410,38 @@ handleAllocSite(Instruction &I, CallBase *CI,
                 const std::set<const AllocationInfo *> &AllocInfoSet,
                 std::map<std::pair<uint64_t, unsigned>, AllocMatchInfo>
                     &FullStackIdToAllocMatchInfo) {
+  // TODO: Remove this once the profile creation logic deduplicates contexts
+  // that are the same other than the IsInlineFrame bool. Until then, keep the
+  // largest.
+  DenseMap<uint64_t, const AllocationInfo *> UniqueFullContextIdAllocInfo;
+  for (auto *AllocInfo : AllocInfoSet) {
+    auto FullStackId = computeFullStackId(AllocInfo->CallStack);
+    auto Insert = UniqueFullContextIdAllocInfo.insert({FullStackId, AllocInfo});
+    // If inserted entry, done.
+    if (Insert.second)
+      continue;
+    // Keep the larger one, or the noncold one if they are the same size.
+    auto CurSize = Insert.first->second->Info.getTotalSize();
+    auto NewSize = AllocInfo->Info.getTotalSize();
+    if ((CurSize > NewSize) ||
+        (CurSize == NewSize &&
+         getAllocType(AllocInfo) != AllocationType::NotCold))
+      continue;
+    Insert.first->second = AllocInfo;
----------------
teresajohnson wrote:

done

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


More information about the llvm-commits mailing list