[lld] r243321 - ELF2: Devirtualize SymbolBody::compare. NFC.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Aug 3 14:56:27 PDT 2015


Thanks!

On 27 July 2015 at 16:39, Rui Ueyama <ruiu at google.com> wrote:
> Author: ruiu
> Date: Mon Jul 27 15:39:01 2015
> New Revision: 243321
>
> URL: http://llvm.org/viewvc/llvm-project?rev=243321&view=rev
> Log:
> ELF2: Devirtualize SymbolBody::compare. NFC.
>
> This is to make it consistent with COFF.
>
> Modified:
>     lld/trunk/ELF/Symbols.cpp
>     lld/trunk/ELF/Symbols.h
>
> Modified: lld/trunk/ELF/Symbols.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=243321&r1=243320&r2=243321&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Symbols.cpp (original)
> +++ lld/trunk/ELF/Symbols.cpp Mon Jul 27 15:39:01 2015
> @@ -21,28 +21,30 @@ DefinedRegular<ELFT>::DefinedRegular(Str
>
>  // Returns 1, 0 or -1 if this symbol should take precedence
>  // over the Other, tie or lose, respectively.
> -template <class ELFT> int DefinedRegular<ELFT>::compare(SymbolBody *Other) {
> -  if (Other->kind() < kind())
> +int SymbolBody::compare(SymbolBody *Other) {
> +  Kind LK = kind();
> +  Kind RK = Other->kind();
> +
> +  // Normalize so that the smaller kind is on the left.
> +  if (LK > RK)
>      return -Other->compare(this);
> -  auto *R = dyn_cast<DefinedRegular>(Other);
> -  if (!R)
> -    return 1;
>
> -  return 0;
> -}
> +  // First handle comparisons between two different kinds.
> +  if (LK != RK) {
> +    assert(LK == DefinedRegularKind);
> +    assert(RK == UndefinedKind);
> +    return 1;
> +  }
>
> -int Defined::compare(SymbolBody *Other) {
> -  if (Other->kind() < kind())
> -    return -Other->compare(this);
> -  if (isa<Defined>(Other))
> +  // Now handle the case where the kinds are the same.
> +  switch (LK) {
> +  case DefinedRegularKind:
>      return 0;
> -  return 1;
> -}
> -
> -int Undefined::compare(SymbolBody *Other) {
> -  if (Other->kind() < kind())
> -    return -Other->compare(this);
> -  return 1;
> +  case UndefinedKind:
> +    return 1;
> +  default:
> +    llvm_unreachable("unknown symbol kind");
> +  }
>  }
>
>  template <class ELFT> StringRef DefinedRegular<ELFT>::getName() { return Name; }
>
> Modified: lld/trunk/ELF/Symbols.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=243321&r1=243320&r2=243321&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Symbols.h (original)
> +++ lld/trunk/ELF/Symbols.h Mon Jul 27 15:39:01 2015
> @@ -61,7 +61,7 @@ public:
>    // Decides which symbol should "win" in the symbol table, this or
>    // the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if
>    // they are duplicate (conflicting) symbols.
> -  virtual int compare(SymbolBody *Other) = 0;
> +  int compare(SymbolBody *Other);
>
>  protected:
>    SymbolBody(Kind K) : SymbolKind(K) {}
> @@ -81,8 +81,6 @@ public:
>      Kind K = S->kind();
>      return DefinedFirst <= K && K <= DefinedLast;
>    }
> -
> -  int compare(SymbolBody *Other) override;
>  };
>
>  // Regular defined symbols read from object file symbol tables.
> @@ -95,7 +93,6 @@ public:
>    }
>
>    StringRef getName() override;
> -  int compare(SymbolBody *Other) override;
>
>  private:
>    StringRef Name;
> @@ -111,8 +108,6 @@ public:
>    }
>    StringRef getName() override { return Name; }
>
> -  int compare(SymbolBody *Other) override;
> -
>  private:
>    StringRef Name;
>  };
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list