[llvm] [memprof] Teach createMIBNode to take ArrayRef (NFC) (PR #111195)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 11:42:34 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

createMIBNode does not modify MIBCallStack, so we can take ArrayRef
instead.

While I am at it, this patch changes the type of MIBPayload to
SmallVector.  We put at most three elements, so we can avoid a heap
allocation.


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


1 Files Affected:

- (modified) llvm/lib/Analysis/MemoryProfileInfo.cpp (+2-3) 


``````````diff
diff --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index 3a752d42241a95..2b49dce17b7931 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -184,10 +184,9 @@ void CallStackTrie::addCallStack(MDNode *MIB) {
   addCallStack(getMIBAllocType(MIB), CallStack, getMIBTotalSize(MIB));
 }
 
-static MDNode *createMIBNode(LLVMContext &Ctx,
-                             std::vector<uint64_t> &MIBCallStack,
+static MDNode *createMIBNode(LLVMContext &Ctx, ArrayRef<uint64_t> MIBCallStack,
                              AllocationType AllocType, uint64_t TotalSize) {
-  std::vector<Metadata *> MIBPayload(
+  SmallVector<Metadata *> MIBPayload(
       {buildCallstackMetadata(MIBCallStack, Ctx)});
   MIBPayload.push_back(
       MDString::get(Ctx, getAllocTypeAttributeString(AllocType)));

``````````

</details>


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


More information about the llvm-commits mailing list