Skip to content

Commit 7ec682b

Browse files
authored
[MC] Use StringRefs from pseudo_probe_desc section if it's mapped
Add `IsMMapped` flag to `buildGUID2FuncDescMap` controlling whether to allocate a string in `FuncNameAllocator` or use StringRef directly. Keep it false by default, only set it for BOLT use case because BOLT keeps file sections in memory while processing them. llvm-profgen constructs GUID2FuncDescMap and then releases the binary. For medium sized binary with 0.8 GiB .pseudo_probe_desc section, this saves 0.7 GiB peak RSS in perf2bolt. Test Plan: no-op for llvm-profgen, NFC for perf2bolt Reviewers: maksfb, dcci, wlei-llvm, rafaelauler, ayermolo Reviewed By: wlei-llvm Pull Request: llvm#112996
1 parent f791cfc commit 7ec682b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

bolt/lib/Rewrite/PseudoProbeRewriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
127127

128128
StringRef Contents = PseudoProbeDescSection->getContents();
129129
if (!ProbeDecoder.buildGUID2FuncDescMap(
130-
reinterpret_cast<const uint8_t *>(Contents.data()),
131-
Contents.size())) {
130+
reinterpret_cast<const uint8_t *>(Contents.data()), Contents.size(),
131+
/*IsMMapped*/ true)) {
132132
errs() << "BOLT-WARNING: fail in building GUID2FuncDescMap\n";
133133
return;
134134
}

llvm/include/llvm/MC/MCPseudoProbe.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ class MCPseudoProbeDecoder {
431431
using Uint64Map = DenseMap<uint64_t, uint64_t>;
432432

433433
// Decode pseudo_probe_desc section to build GUID to PseudoProbeFuncDesc map.
434-
bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size);
434+
// If pseudo_probe_desc section is mapped to memory and \p IsMMapped is true,
435+
// uses StringRefs pointing to the section.
436+
bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size,
437+
bool IsMMapped = false);
435438

436439
// Decode pseudo_probe section to count the number of probes and inlined
437440
// function records for each function record.

llvm/lib/MC/MCPseudoProbe.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ ErrorOr<StringRef> MCPseudoProbeDecoder::readString(uint32_t Size) {
375375
}
376376

377377
bool MCPseudoProbeDecoder::buildGUID2FuncDescMap(const uint8_t *Start,
378-
std::size_t Size) {
378+
std::size_t Size,
379+
bool IsMMapped) {
379380
// The pseudo_probe_desc section has a format like:
380381
// .section .pseudo_probe_desc,"",@progbits
381382
// .quad -5182264717993193164 // GUID
@@ -422,7 +423,8 @@ bool MCPseudoProbeDecoder::buildGUID2FuncDescMap(const uint8_t *Start,
422423
StringRef Name = cantFail(errorOrToExpected(readString(NameSize)));
423424

424425
// Initialize PseudoProbeFuncDesc and populate it into GUID2FuncDescMap
425-
GUID2FuncDescMap.emplace_back(GUID, Hash, Name.copy(FuncNameAllocator));
426+
GUID2FuncDescMap.emplace_back(
427+
GUID, Hash, IsMMapped ? Name : Name.copy(FuncNameAllocator));
426428
}
427429
assert(Data == End && "Have unprocessed data in pseudo_probe_desc section");
428430
assert(GUID2FuncDescMap.size() == FuncDescCount &&

0 commit comments

Comments
 (0)