-
Notifications
You must be signed in to change notification settings - Fork 15k
[MC] Use StringRefs from pseudo_probe_desc section if it's mapped #112996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MC] Use StringRefs from pseudo_probe_desc section if it's mapped #112996
Conversation
Created using spr 1.3.4
Created using spr 1.3.4 [skip ci]
@llvm/pr-subscribers-bolt @llvm/pr-subscribers-mc Author: Amir Ayupov (aaupov) ChangesAdd This saves ~0.7 GiB peak RSS in perf2bolt processing a medium sized This is because BOLT keeps file sections in memory while processing them Test Plan: no-op for llvm-profgen, NFC for perf2bolt Full diff: https://github.com/llvm/llvm-project/pull/112996.diff 3 Files Affected:
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,"",@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 &&
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Created using spr 1.3.4
ping @wlei-llvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, LGTM.
Created using spr 1.3.4 [skip ci]
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
Add
IsMMapped
flag tobuildGUID2FuncDescMap
controlling whether toallocate 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