forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
71b3bfde9c
commit
417cd2e5c5
|
@ -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)
|
||||
|
|
|
@ -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 @@ public:
|
|||
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 @@ private:
|
|||
// 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 different 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;
|
||||
|
|
Loading…
Reference in New Issue