[llvm-branch-commits] [MC] Use StringRefs from pseudo_probe_desc section if it's mapped (PR #112996)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 18 16:10:05 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mc
Author: Amir Ayupov (aaupov)
<details>
<summary>Changes</summary>
Add `IsMMapped` flag to `buildGUID2FuncDescMap` controlling whether to
allocate a string in `FuncNameAllocator` or use StringRef directly.
This saves ~0.7 GiB peak RSS in perf2bolt processing a medium sized
binary with ~0.8 GiB .pseudo_probe_desc section.
This is because BOLT keeps file sections in memory while processing them
whereas llvm-profgen constructs GUID2FuncDescMap and then releases the
binary.
Test Plan: no-op for llvm-profgen, NFC for perf2bolt
---
Full diff: https://github.com/llvm/llvm-project/pull/112996.diff
3 Files Affected:
- (modified) bolt/lib/Rewrite/PseudoProbeRewriter.cpp (+1-1)
- (modified) llvm/include/llvm/MC/MCPseudoProbe.h (+4-1)
- (modified) llvm/lib/MC/MCPseudoProbe.cpp (+4-2)
``````````diff
diff --git a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
index 8647df4b0edf82..4fecfe8c3c09b1 100644
--- a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
+++ b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp
@@ -128,7 +128,7 @@ void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
StringRef Contents = PseudoProbeDescSection->getContents();
if (!ProbeDecoder.buildGUID2FuncDescMap(
reinterpret_cast<const uint8_t *>(Contents.data()),
- Contents.size())) {
+ Contents.size(), /*IsMMapped*/true)) {
errs() << "BOLT-WARNING: fail in building GUID2FuncDescMap\n";
return;
}
diff --git a/llvm/include/llvm/MC/MCPseudoProbe.h b/llvm/include/llvm/MC/MCPseudoProbe.h
index 4bfae9eba1a0aa..fd1f0557895446 100644
--- a/llvm/include/llvm/MC/MCPseudoProbe.h
+++ b/llvm/include/llvm/MC/MCPseudoProbe.h
@@ -431,7 +431,10 @@ class MCPseudoProbeDecoder {
using Uint64Map = DenseMap<uint64_t, uint64_t>;
// Decode pseudo_probe_desc section to build GUID to PseudoProbeFuncDesc map.
- bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size);
+ // If pseudo_probe_desc section is mapped to memory and \p IsMMapped is true,
+ // uses StringRefs pointing to the section.
+ bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size,
+ bool IsMMapped = false);
// Decode pseudo_probe section to count the number of probes and inlined
// function records for each function record.
diff --git a/llvm/lib/MC/MCPseudoProbe.cpp b/llvm/lib/MC/MCPseudoProbe.cpp
index 90d7588407068a..2a3761b2cfe718 100644
--- a/llvm/lib/MC/MCPseudoProbe.cpp
+++ b/llvm/lib/MC/MCPseudoProbe.cpp
@@ -375,7 +375,8 @@ ErrorOr<StringRef> MCPseudoProbeDecoder::readString(uint32_t Size) {
}
bool MCPseudoProbeDecoder::buildGUID2FuncDescMap(const uint8_t *Start,
- std::size_t Size) {
+ std::size_t Size,
+ bool IsMMapped) {
// The pseudo_probe_desc section has a format like:
// .section .pseudo_probe_desc,"", at progbits
// .quad -5182264717993193164 // GUID
@@ -422,7 +423,8 @@ bool MCPseudoProbeDecoder::buildGUID2FuncDescMap(const uint8_t *Start,
StringRef Name = cantFail(errorOrToExpected(readString(NameSize)));
// Initialize PseudoProbeFuncDesc and populate it into GUID2FuncDescMap
- GUID2FuncDescMap.emplace_back(GUID, Hash, Name.copy(FuncNameAllocator));
+ GUID2FuncDescMap.emplace_back(
+ GUID, Hash, IsMMapped ? Name : Name.copy(FuncNameAllocator));
}
assert(Data == End && "Have unprocessed data in pseudo_probe_desc section");
assert(GUID2FuncDescMap.size() == FuncDescCount &&
``````````
</details>
https://github.com/llvm/llvm-project/pull/112996
More information about the llvm-branch-commits
mailing list