[llvm] [BOLT][NFC] Store FILE symbols in a vector (PR #89088)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 17 09:15:09 PDT 2024
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/89088
>From 1f821db5090237d0eee70caece0a4f994768f539 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Wed, 17 Apr 2024 16:14:46 +0200
Subject: [PATCH] [BOLT][NFC] Keep FILE symbols in a vector
In discoverFileObjects, replace mapping from every local symbol to
associated file name with a vector of symbol data for FILE symbols
only. This cuts down on memory needed to resolve local file names.
Test Plan: NFC
---
bolt/lib/Rewrite/RewriteInstance.cpp | 33 ++++++++++------------------
1 file changed, 12 insertions(+), 21 deletions(-)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 0c8ee0d417233b..916a74095f58b7 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -813,14 +813,7 @@ void RewriteInstance::discoverFileObjects() {
// For local symbols we want to keep track of associated FILE symbol name for
// disambiguation by combined name.
- StringRef FileSymbolName;
- bool SeenFileName = false;
- struct SymbolRefHash {
- size_t operator()(SymbolRef const &S) const {
- return std::hash<decltype(DataRefImpl::p)>{}(S.getRawDataRefImpl().p);
- }
- };
- std::unordered_map<SymbolRef, StringRef, SymbolRefHash> SymbolToFileName;
+ std::vector<DataRefImpl> FileSymbols;
for (const ELFSymbolRef &Symbol : InputFile->symbols()) {
Expected<StringRef> NameOrError = Symbol.getName();
if (NameOrError && NameOrError->starts_with("__asan_init")) {
@@ -846,13 +839,8 @@ void RewriteInstance::discoverFileObjects() {
// and this uncertainty is causing havoc in function name matching.
if (Name == "ld-temp.o")
continue;
- FileSymbolName = Name;
- SeenFileName = true;
- continue;
+ FileSymbols.emplace_back(Symbol.getRawDataRefImpl());
}
- if (!FileSymbolName.empty() &&
- !(cantFail(Symbol.getFlags()) & SymbolRef::SF_Global))
- SymbolToFileName[Symbol] = FileSymbolName;
}
// Sort symbols in the file by value. Ignore symbols from non-allocatable
@@ -1027,14 +1015,17 @@ void RewriteInstance::discoverFileObjects() {
// The <id> field is used for disambiguation of local symbols since there
// could be identical function names coming from identical file names
// (e.g. from different directories).
- std::string AltPrefix;
- auto SFI = SymbolToFileName.find(Symbol);
- if (SymbolType == SymbolRef::ST_Function && SFI != SymbolToFileName.end())
- AltPrefix = Name + "/" + std::string(SFI->second);
+ auto CompareSymsByIdx = [](const DataRefImpl &A, const DataRefImpl &B) {
+ return A.d.b < B.d.b;
+ };
+ DataRefImpl SymDataRef = Symbol.getRawDataRefImpl();
+ auto It = llvm::upper_bound(FileSymbols, SymDataRef, CompareSymsByIdx);
+ if (SymbolType == SymbolRef::ST_Function && It != FileSymbols.begin()) {
+ StringRef FileName = cantFail(SymbolRef(It[-1], InputFile).getName());
+ AlternativeName = NR.uniquify(Name + "/" + FileName.str());
+ }
UniqueName = NR.uniquify(Name);
- if (!AltPrefix.empty())
- AlternativeName = NR.uniquify(AltPrefix);
}
uint64_t SymbolSize = ELFSymbolRef(Symbol).getSize();
@@ -1285,7 +1276,7 @@ void RewriteInstance::discoverFileObjects() {
FDE->getAddressRange());
}
- BC->setHasSymbolsWithFileName(SeenFileName);
+ BC->setHasSymbolsWithFileName(!FileSymbols.empty());
// Now that all the functions were created - adjust their boundaries.
adjustFunctionBoundaries();
More information about the llvm-commits
mailing list