[llvm] [MemProf] Fix when CallStackTrie is a single chain with multi alloc type (PR #79433)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 02:17:40 PST 2024


https://github.com/lifengxiang1025 created https://github.com/llvm/llvm-project/pull/79433

Fix one corner case when `CallStackTrie` is a single chain with multi alloc type. This will cause stackIds in function summary is empty.

>From 311548f0e9140dd4e607c23c597ddeeb57538fc9 Mon Sep 17 00:00:00 2001
From: lifengxiang <lifengxiang.1025 at bytedance.com>
Date: Thu, 25 Jan 2024 18:15:00 +0800
Subject: [PATCH] [MemProf] Fix when CallStackTrie is a single chain with multi
 alloc type

---
 llvm/lib/Analysis/MemoryProfileInfo.cpp | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index 7fbcffc6489dcfd..7fbbc280348c079 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -244,12 +244,14 @@ bool CallStackTrie::buildAndAttachMIBMetadata(CallBase *CI) {
   MIBCallStack.push_back(AllocStackId);
   std::vector<Metadata *> MIBNodes;
   assert(!Alloc->Callers.empty() && "addCallStack has not been called yet");
-  buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes,
-                /*CalleeHasAmbiguousCallerContext=*/true);
-  assert(MIBCallStack.size() == 1 &&
-         "Should only be left with Alloc's location in stack");
-  CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes));
-  return true;
+  if (buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes,
+                    Alloc->Callers.size() > 1)) {
+    assert(MIBCallStack.size() == 1 &&
+           "Should only be left with Alloc's location in stack");
+    CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes));
+    return true;
+  }
+  return false;
 }
 
 template <>



More information about the llvm-commits mailing list