[lld] r266357 - Hash symbol names only once per global SymbolBody.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 20:17:12 PDT 2016


Was this commit intentional. Wasn't D19045 the intended solution?

-- Sean Silva

On Thu, Apr 14, 2016 at 12:17 PM, Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: rafael
> Date: Thu Apr 14 14:17:16 2016
> New Revision: 266357
>
> URL: http://llvm.org/viewvc/llvm-project?rev=266357&view=rev
> Log:
> Hash symbol names only once per global SymbolBody.
>
> The DenseMap doesn't store hash results. This means that when it is
> resized it has to recompute them.
>
> This patch is a small hack that wraps the StringRef in a struct that
> remembers the hash value. That way we can be sure it is only hashed
> once.
>
> Modified:
>     lld/trunk/ELF/MarkLive.cpp
>     lld/trunk/ELF/SymbolTable.h
>
> Modified: lld/trunk/ELF/MarkLive.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=266357&r1=266356&r2=266357&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/MarkLive.cpp (original)
> +++ lld/trunk/ELF/MarkLive.cpp Thu Apr 14 14:17:16 2016
> @@ -113,7 +113,7 @@ template <class ELFT> void elf::markLive
>    // Preserve externally-visible symbols if the symbols defined by this
>    // file can interrupt other ELF file's symbols at runtime.
>    if (Config->Shared || Config->ExportDynamic) {
> -    for (const std::pair<StringRef, Symbol *> &P : Symtab->getSymbols()) {
> +    for (const std::pair<SymName, Symbol *> &P : Symtab->getSymbols()) {
>        SymbolBody *B = P.second->Body;
>        if (B->getVisibility() == STV_DEFAULT)
>          MarkSymbol(B);
>
> Modified: lld/trunk/ELF/SymbolTable.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=266357&r1=266356&r2=266357&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.h (original)
> +++ lld/trunk/ELF/SymbolTable.h Thu Apr 14 14:17:16 2016
> @@ -20,6 +20,37 @@ class Lazy;
>  template <class ELFT> class OutputSectionBase;
>  struct Symbol;
>
> +struct SymName {
> +  SymName(StringRef Name) : Name(Name) {
> +    Hash = llvm::DenseMapInfo<StringRef>::getHashValue(Name);
> +  }
> +  SymName(StringRef Name, unsigned Hash) : Name(Name), Hash(Hash) {}
> +  StringRef Name;
> +  unsigned Hash;
> +};
> +}
> +}
> +
> +namespace llvm {
> +template <> struct DenseMapInfo<lld::elf::SymName> {
> +  static lld::elf::SymName getEmptyKey() {
> +    StringRef N = DenseMapInfo<StringRef>::getEmptyKey();
> +    return {N, 0};
> +  }
> +  static lld::elf::SymName getTombstoneKey() {
> +    StringRef N = DenseMapInfo<StringRef>::getTombstoneKey();
> +    return {N, 0};
> +  }
> +  static unsigned getHashValue(lld::elf::SymName Name) { return
> Name.Hash; }
> +  static bool isEqual(lld::elf::SymName A, lld::elf::SymName B) {
> +    return A.Name == B.Name;
> +  }
> +};
> +}
> +
> +namespace lld {
> +namespace elf {
> +
>  // SymbolTable is a bucket of all known symbols, including defined,
>  // undefined, or lazy symbols (the last one is symbols in archive
>  // files whose archive members are not yet loaded).
> @@ -38,7 +69,7 @@ public:
>    void addFile(std::unique_ptr<InputFile> File);
>    void addCombinedLtoObject();
>
> -  const llvm::MapVector<StringRef, Symbol *> &getSymbols() const {
> +  const llvm::MapVector<SymName, Symbol *> &getSymbols() const {
>      return Symtab;
>    }
>
> @@ -79,7 +110,7 @@ private:
>    // a bit inefficient.
>    // FIXME: Experiment with passing in a custom hashing or sorting the
> symbols
>    // once symbol resolution is finished.
> -  llvm::MapVector<StringRef, Symbol *> Symtab;
> +  llvm::MapVector<SymName, Symbol *> Symtab;
>    llvm::BumpPtrAllocator Alloc;
>
>    // Comdat groups define "link once" sections. If two comdat groups have
> the
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160414/ae37087f/attachment-0001.html>


More information about the llvm-commits mailing list