ELF2: Devirtualize SymbolBody::compare. NFC.

This is to make it consistent with COFF.

llvm-svn: 243321
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 7d9a185..c711785 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -21,28 +21,30 @@
 
 // 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)
+
+  // First handle comparisons between two different kinds.
+  if (LK != RK) {
+    assert(LK == DefinedRegularKind);
+    assert(RK == UndefinedKind);
     return 1;
+  }
 
-  return 0;
-}
-
-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; }
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 975302e..de6f806 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -61,7 +61,7 @@
   // 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 @@
     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 @@
   }
 
   StringRef getName() override;
-  int compare(SymbolBody *Other) override;
 
 private:
   StringRef Name;
@@ -111,8 +108,6 @@
   }
   StringRef getName() override { return Name; }
 
-  int compare(SymbolBody *Other) override;
-
 private:
   StringRef Name;
 };