[lld] r243701 - COFF: Move code for Identical COMDAT Folding to ICF.cpp.

Rui Ueyama ruiu at google.com
Thu Jul 30 15:57:21 PDT 2015


Author: ruiu
Date: Thu Jul 30 17:57:21 2015
New Revision: 243701

URL: http://llvm.org/viewvc/llvm-project?rev=243701&view=rev
Log:
COFF: Move code for Identical COMDAT Folding to ICF.cpp.

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/COFF/ICF.cpp

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=243701&r1=243700&r2=243701&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Thu Jul 30 17:57:21 2015
@@ -10,8 +10,6 @@
 #include "Chunks.h"
 #include "InputFiles.h"
 #include "Writer.h"
-#include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/Object/COFF.h"
 #include "llvm/Support/COFF.h"
 #include "llvm/Support/Debug.h"
@@ -211,58 +209,6 @@ StringRef SectionChunk::getDebugName() {
   return Sym->getName();
 }
 
-uint64_t SectionChunk::getHash() const {
-  ArrayRef<uint8_t> A = getContents();
-  return hash_combine(getPermissions(),
-                      llvm::hash_value(SectionName),
-                      NumRelocs,
-                      uint32_t(Header->SizeOfRawData),
-                      std::distance(Relocs.end(), Relocs.begin()),
-                      hash_combine_range(A.data(), A.data() + A.size()));
-}
-
-// Returns true if this and a given chunk are identical COMDAT sections.
-bool SectionChunk::equals(const SectionChunk *X) const {
-  // Compare headers
-  if (getPermissions() != X->getPermissions())
-    return false;
-  if (SectionName != X->SectionName)
-    return false;
-  if (Header->SizeOfRawData != X->Header->SizeOfRawData)
-    return false;
-  if (NumRelocs != X->NumRelocs)
-    return false;
-
-  // Compare data
-  if (getContents() != X->getContents())
-    return false;
-
-  // Compare associative sections
-  if (AssocChildren.size() != X->AssocChildren.size())
-    return false;
-  for (size_t I = 0, E = AssocChildren.size(); I != E; ++I)
-    if (AssocChildren[I]->Ptr != X->AssocChildren[I]->Ptr)
-      return false;
-
-  // Compare relocations
-  auto Eq = [&](const coff_relocation &R1, const coff_relocation &R2) {
-    if (R1.Type != R2.Type)
-      return false;
-    if (R1.VirtualAddress != R2.VirtualAddress)
-      return false;
-    SymbolBody *B1 = File->getSymbolBody(R1.SymbolTableIndex)->repl();
-    SymbolBody *B2 = X->File->getSymbolBody(R2.SymbolTableIndex)->repl();
-    if (B1 == B2)
-      return true;
-    auto *D1 = dyn_cast<DefinedRegular>(B1);
-    auto *D2 = dyn_cast<DefinedRegular>(B2);
-    return (D1 && D2 &&
-            D1->getValue() == D2->getValue() &&
-            D1->getChunk() == D2->getChunk());
-  };
-  return std::equal(Relocs.begin(), Relocs.end(), X->Relocs.begin(), Eq);
-}
-
 ArrayRef<uint8_t> SectionChunk::getContents() const {
   ArrayRef<uint8_t> A;
   File->getCOFFObj()->getSectionContents(Header, A);

Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=243701&r1=243700&r2=243701&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Thu Jul 30 17:57:21 2015
@@ -12,10 +12,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "Chunks.h"
+#include "Symbols.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/STLExtras.h"
 #include <tuple>
 #include <unordered_set>
 #include <vector>
 
+using namespace llvm;
+
 namespace lld {
 namespace coff {
 namespace {
@@ -32,6 +37,58 @@ struct Equals {
 
 } // anonymous namespace
 
+uint64_t SectionChunk::getHash() const {
+  ArrayRef<uint8_t> A = getContents();
+  return hash_combine(getPermissions(),
+                      hash_value(SectionName),
+                      NumRelocs,
+                      uint32_t(Header->SizeOfRawData),
+                      std::distance(Relocs.end(), Relocs.begin()),
+                      hash_combine_range(A.data(), A.data() + A.size()));
+}
+
+// Returns true if this and a given chunk are identical COMDAT sections.
+bool SectionChunk::equals(const SectionChunk *X) const {
+  // Compare headers
+  if (getPermissions() != X->getPermissions())
+    return false;
+  if (SectionName != X->SectionName)
+    return false;
+  if (Header->SizeOfRawData != X->Header->SizeOfRawData)
+    return false;
+  if (NumRelocs != X->NumRelocs)
+    return false;
+
+  // Compare data
+  if (getContents() != X->getContents())
+    return false;
+
+  // Compare associative sections
+  if (AssocChildren.size() != X->AssocChildren.size())
+    return false;
+  for (size_t I = 0, E = AssocChildren.size(); I != E; ++I)
+    if (AssocChildren[I]->Ptr != X->AssocChildren[I]->Ptr)
+      return false;
+
+  // Compare relocations
+  auto Eq = [&](const coff_relocation &R1, const coff_relocation &R2) {
+    if (R1.Type != R2.Type)
+      return false;
+    if (R1.VirtualAddress != R2.VirtualAddress)
+      return false;
+    SymbolBody *B1 = File->getSymbolBody(R1.SymbolTableIndex)->repl();
+    SymbolBody *B2 = X->File->getSymbolBody(R2.SymbolTableIndex)->repl();
+    if (B1 == B2)
+      return true;
+    auto *D1 = dyn_cast<DefinedRegular>(B1);
+    auto *D2 = dyn_cast<DefinedRegular>(B2);
+    return (D1 && D2 &&
+            D1->getValue() == D2->getValue() &&
+            D1->getChunk() == D2->getChunk());
+  };
+  return std::equal(Relocs.begin(), Relocs.end(), X->Relocs.begin(), Eq);
+}
+
 // Merge identical COMDAT sections.
 // Two sections are considered as identical when their section headers,
 // contents and relocations are all the same.





More information about the llvm-commits mailing list