[lld] 417cd2e - [ELF] SymbolTable: change some vector<Symbol *> to SmallVector
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 23 16:49:42 PST 2021
Author: Fangrui Song
Date: 2021-12-23T16:49:38-08:00
New Revision: 417cd2e5c5e0ef0a3c8161298b7690f7911ce7ed
URL: https://github.com/llvm/llvm-project/commit/417cd2e5c5e0ef0a3c8161298b7690f7911ce7ed
DIFF: https://github.com/llvm/llvm-project/commit/417cd2e5c5e0ef0a3c8161298b7690f7911ce7ed.diff
LOG: [ELF] SymbolTable: change some vector<Symbol *> to SmallVector
The generated assembly for Symbol::insert is much shorter (std::vector resize is
inefficient) and enables some inlining.
Added:
Modified:
lld/ELF/SymbolTable.cpp
lld/ELF/SymbolTable.h
Removed:
################################################################################
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 5c7b8b00a6eea..a501b270010bf 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -133,7 +133,7 @@ static bool canBeVersioned(const Symbol &sym) {
// other than trying to match a pattern against all demangled symbols.
// So, if "extern C++" feature is used, we need to demangle all known
// symbols.
-StringMap<std::vector<Symbol *>> &SymbolTable::getDemangledSyms() {
+StringMap<SmallVector<Symbol *, 0>> &SymbolTable::getDemangledSyms() {
if (!demangledSyms) {
demangledSyms.emplace();
std::string demangled;
@@ -154,7 +154,7 @@ StringMap<std::vector<Symbol *>> &SymbolTable::getDemangledSyms() {
return *demangledSyms;
}
-std::vector<Symbol *> SymbolTable::findByVersion(SymbolVersion ver) {
+SmallVector<Symbol *, 0> SymbolTable::findByVersion(SymbolVersion ver) {
if (ver.isExternCpp)
return getDemangledSyms().lookup(ver.name);
if (Symbol *sym = find(ver.name))
@@ -163,9 +163,9 @@ std::vector<Symbol *> SymbolTable::findByVersion(SymbolVersion ver) {
return {};
}
-std::vector<Symbol *> SymbolTable::findAllByVersion(SymbolVersion ver,
- bool includeNonDefault) {
- std::vector<Symbol *> res;
+SmallVector<Symbol *, 0> SymbolTable::findAllByVersion(SymbolVersion ver,
+ bool includeNonDefault) {
+ SmallVector<Symbol *, 0> res;
SingleStringMatcher m(ver.name);
auto check = [&](StringRef name) {
size_t pos = name.find('@');
@@ -191,8 +191,8 @@ std::vector<Symbol *> SymbolTable::findAllByVersion(SymbolVersion ver,
}
void SymbolTable::handleDynamicList() {
+ SmallVector<Symbol *, 0> syms;
for (SymbolVersion &ver : config->dynamicList) {
- std::vector<Symbol *> syms;
if (ver.hasWildcard)
syms = findAllByVersion(ver, /*includeNonDefault=*/true);
else
@@ -209,7 +209,7 @@ bool SymbolTable::assignExactVersion(SymbolVersion ver, uint16_t versionId,
StringRef versionName,
bool includeNonDefault) {
// Get a list of symbols which we need to assign the version to.
- std::vector<Symbol *> syms = findByVersion(ver);
+ SmallVector<Symbol *, 0> syms = findByVersion(ver);
auto getName = [](uint16_t ver) -> std::string {
if (ver == VER_NDX_LOCAL)
diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h
index 568e4559ec346..84d93a3dc7863 100644
--- a/lld/ELF/SymbolTable.h
+++ b/lld/ELF/SymbolTable.h
@@ -35,8 +35,9 @@ class SymbolTable {
struct FilterOutPlaceholder {
bool operator()(Symbol *S) const { return !S->isPlaceholder(); }
};
- using iterator = llvm::filter_iterator<std::vector<Symbol *>::const_iterator,
- FilterOutPlaceholder>;
+ using iterator =
+ llvm::filter_iterator<SmallVector<Symbol *, 0>::const_iterator,
+ FilterOutPlaceholder>;
public:
llvm::iterator_range<iterator> symbols() const {
@@ -64,11 +65,11 @@ class SymbolTable {
llvm::DenseMap<llvm::CachedHashStringRef, const InputFile *> comdatGroups;
private:
- std::vector<Symbol *> findByVersion(SymbolVersion ver);
- std::vector<Symbol *> findAllByVersion(SymbolVersion ver,
- bool includeNonDefault);
+ SmallVector<Symbol *, 0> findByVersion(SymbolVersion ver);
+ SmallVector<Symbol *, 0> findAllByVersion(SymbolVersion ver,
+ bool includeNonDefault);
- llvm::StringMap<std::vector<Symbol *>> &getDemangledSyms();
+ llvm::StringMap<SmallVector<Symbol *, 0>> &getDemangledSyms();
bool assignExactVersion(SymbolVersion ver, uint16_t versionId,
StringRef versionName, bool includeNonDefault);
void assignWildcardVersion(SymbolVersion ver, uint16_t versionId,
@@ -82,13 +83,13 @@ class SymbolTable {
// FIXME: Experiment with passing in a custom hashing or sorting the symbols
// once symbol resolution is finished.
llvm::DenseMap<llvm::CachedHashStringRef, int> symMap;
- std::vector<Symbol *> symVector;
+ SmallVector<Symbol *, 0> symVector;
// A map from demangled symbol names to their symbol objects.
// This mapping is 1:N because two symbols with
diff erent versions
// can have the same name. We use this map to handle "extern C++ {}"
// directive in version scripts.
- llvm::Optional<llvm::StringMap<std::vector<Symbol *>>> demangledSyms;
+ llvm::Optional<llvm::StringMap<SmallVector<Symbol *, 0>>> demangledSyms;
};
extern std::unique_ptr<SymbolTable> symtab;
More information about the llvm-commits
mailing list