[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:18:10 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: None (lifengxiang1025)

<details>
<summary>Changes</summary>

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

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


1 Files Affected:

- (modified) llvm/lib/Analysis/MemoryProfileInfo.cpp (+8-6) 


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

``````````

</details>


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


More information about the llvm-commits mailing list