[llvm] [memprof] Use SmallVector for InlinedCallStack (NFC) (PR #114599)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 1 12:45:34 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/114599
We can stay within 8 inlined elements more than 99% of the time while
building a large application.
>From a51937a484e000e5fea3bd9be7d909e3dbbec147 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 1 Nov 2024 12:10:37 -0700
Subject: [PATCH] [memprof] Use SmallVector for InlinedCallStack (NFC)
We can stay within 8 inlined elements more than 99% of the time while
building a large application.
---
llvm/lib/Analysis/MemoryProfileInfo.cpp | 3 ++-
llvm/lib/Transforms/Instrumentation/MemProfiler.cpp | 4 ++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index 2b49dce17b7931..d3d125893377a8 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -69,7 +69,8 @@ AllocationType llvm::memprof::getAllocType(uint64_t TotalLifetimeAccessDensity,
MDNode *llvm::memprof::buildCallstackMetadata(ArrayRef<uint64_t> CallStack,
LLVMContext &Ctx) {
- std::vector<Metadata *> StackVals;
+ SmallVector<Metadata *, 8> StackVals;
+ StackVals.reserve(CallStack.size());
for (auto Id : CallStack) {
auto *StackValMD =
ValueAsMetadata::get(ConstantInt::get(Type::getInt64Ty(Ctx), Id));
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
index 4a43120c9a9e7f..248d72ea2cca84 100644
--- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
@@ -680,7 +680,7 @@ bool MemProfiler::instrumentFunction(Function &F) {
}
static void addCallsiteMetadata(Instruction &I,
- std::vector<uint64_t> &InlinedCallStack,
+ ArrayRef<uint64_t> InlinedCallStack,
LLVMContext &Ctx) {
I.setMetadata(LLVMContext::MD_callsite,
buildCallstackMetadata(InlinedCallStack, Ctx));
@@ -905,7 +905,7 @@ readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
continue;
// List of call stack ids computed from the location hashes on debug
// locations (leaf to inlined at root).
- std::vector<uint64_t> InlinedCallStack;
+ SmallVector<uint64_t, 8> InlinedCallStack;
// Was the leaf location found in one of the profile maps?
bool LeafFound = false;
// If leaf was found in a map, iterators pointing to its location in both
More information about the llvm-commits
mailing list