[PATCH] D54773: ELF: ICF: Include contents of referenced sections in initial partitioning hash. NFCI.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 20 13:39:42 PST 2018


pcc created this revision.
pcc added reviewers: ruiu, grimar.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.

On my machine this reduced median link time of lld-speed-test/chrome
from 2.68s to 2.41s. It also reduces link time of Chrome for Android
with a prototype compiler change that causes the compiler to create
large numbers of identical (modulo relocations) sections from >15
minutes to a few seconds.


Repository:
  rL LLVM

https://reviews.llvm.org/D54773

Files:
  lld/ELF/ICF.cpp


Index: lld/ELF/ICF.cpp
===================================================================
--- lld/ELF/ICF.cpp
+++ lld/ELF/ICF.cpp
@@ -119,6 +119,9 @@
 
   void forEachClass(llvm::function_ref<void(size_t, size_t)> Fn);
 
+  template <class RelTy>
+  void combineRelocHashes(InputSection *IS, ArrayRef<RelTy> Rels);
+
   std::vector<InputSection *> Sections;
 
   // We repeat the main loop while `Repeat` is true.
@@ -423,6 +426,22 @@
   ++Cnt;
 }
 
+// Combine the hashes of the sections referenced by the given section into its
+// hash.
+template <class ELFT>
+template <class RelTy>
+void ICF<ELFT>::combineRelocHashes(InputSection *IS, ArrayRef<RelTy> Rels) {
+  uint32_t Hash = IS->Class[1];
+  for (RelTy Rel : Rels) {
+    Symbol &S = IS->template getFile<ELFT>()->getRelocTargetSym(Rel);
+    if (auto *D = dyn_cast<Defined>(&S))
+      if (auto *RelSec = dyn_cast_or_null<InputSection>(D->Section))
+        Hash ^= RelSec->Class[1];
+  }
+  // Set MSB to 1 to avoid collisions with non-hash IDs.
+  IS->Class[0] = Hash | (1U << 31);
+}
+
 static void print(const Twine &S) {
   if (Config->PrintIcfSections)
     message(S);
@@ -438,8 +457,14 @@
 
   // Initially, we use hash values to partition sections.
   parallelForEach(Sections, [&](InputSection *S) {
-    // Set MSB to 1 to avoid collisions with non-hash IDs.
-    S->Class[0] = xxHash64(S->data()) | (1U << 31);
+    S->Class[1] = xxHash64(S->data());
+  });
+
+  parallelForEach(Sections, [&](InputSection *S) {
+    if (S->AreRelocsRela)
+      combineRelocHashes(S, S->template relas<ELFT>());
+    else
+      combineRelocHashes(S, S->template rels<ELFT>());
   });
 
   // From now on, sections in Sections vector are ordered so that sections


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54773.174833.patch
Type: text/x-patch
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181120/3c2c8387/attachment.bin>


More information about the llvm-commits mailing list