[llvm] [memprof] Use a SetVector (NFC) (PR #93312)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri May 24 08:19:24 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/93312
None
>From 3d74a922dc05424e166970de7ed47e4937712c8b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 24 May 2024 06:18:46 -0700
Subject: [PATCH] [memprof] Use a SetVector (NFC)
---
llvm/lib/ProfileData/MemProfReader.cpp | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index c25babac844ac..fc3be716087eb 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -587,31 +587,27 @@ Error RawMemProfReader::symbolizeAndFilterStackFrames(
std::vector<std::string>
RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) {
const char *Next = DataBuffer->getBufferStart();
- // Use a set + vector since a profile file may contain multiple raw profile
+ // Use a SetVector since a profile file may contain multiple raw profile
// dumps, each with segment information. We want them unique and in order they
// were stored in the profile; the profiled binary should be the first entry.
// The runtime uses dl_iterate_phdr and the "... first object visited by
// callback is the main program."
// https://man7.org/linux/man-pages/man3/dl_iterate_phdr.3.html
- std::vector<std::string> BuildIds;
- llvm::SmallSet<std::string, 10> BuildIdsSet;
+ llvm::SetVector<std::string, std::vector<std::string>,
+ llvm::SmallSet<std::string, 10>>
+ BuildIds;
while (Next < DataBuffer->getBufferEnd()) {
auto *Header = reinterpret_cast<const memprof::Header *>(Next);
const llvm::SmallVector<SegmentEntry> Entries =
readSegmentEntries(Next + Header->SegmentOffset);
- for (const auto &Entry : Entries) {
- const std::string Id = getBuildIdString(Entry);
- if (BuildIdsSet.contains(Id))
- continue;
- BuildIds.push_back(Id);
- BuildIdsSet.insert(Id);
- }
+ for (const auto &Entry : Entries)
+ BuildIds.insert(getBuildIdString(Entry));
Next += Header->TotalSize;
}
- return BuildIds;
+ return BuildIds.takeVector();
}
Error RawMemProfReader::readRawProfile(
More information about the llvm-commits
mailing list