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

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


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

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.


>From a22a4b3f699318f0b464b208c077f1f8dc694a9d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 4 Oct 2024 11:31:04 -0700
Subject: [PATCH] [memprof] Teach createMIBNode to take ArrayRef (NFC)

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.
---
 llvm/lib/Analysis/MemoryProfileInfo.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

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)));



More information about the llvm-commits mailing list