[lld] r268639 - Cache result when tail merging too.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 09:12:25 PDT 2016


Author: rafael
Date: Thu May  5 11:12:25 2016
New Revision: 268639

URL: http://llvm.org/viewvc/llvm-project?rev=268639&view=rev
Log:
Cache result when tail merging too.

This speeds up a link of chromium with -O2 (but no icf,gc) from
1.940664632 to 1.925578119.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=268639&r1=268638&r2=268639&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu May  5 11:12:25 2016
@@ -479,14 +479,15 @@ typename ELFT::uint MergeInputSection<EL
   // Compute the Addend and if the Base is cached, return.
   uintX_t Addend = Offset - Start;
   uintX_t &Base = I->second;
-  auto *MOS = static_cast<MergeOutputSection<ELFT> *>(this->OutSec);
-  if (!MOS->shouldTailMerge())
+  assert(Base != MergeInputSection<ELFT>::PieceDead);
+  if (Base != MergeInputSection<ELFT>::PieceLive)
     return Base + Addend;
 
   // Map the base to the offset in the output section and cache it.
   ArrayRef<uint8_t> D = this->getSectionData();
   StringRef Data((const char *)D.data(), D.size());
   StringRef Entry = Data.substr(Start, End - Start);
+  auto *MOS = static_cast<MergeOutputSection<ELFT> *>(this->OutSec);
   Base = MOS->getOffset(Entry);
   return Base + Addend;
 }

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=268639&r1=268638&r2=268639&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Thu May  5 11:12:25 2016
@@ -152,12 +152,11 @@ public:
   enum {
     // The piece is dead.
     PieceDead = uintX_t(-1),
-    // The piece is live, and an offset has not yet been assigned. After offsets
+    // The piece is live, but an offset has not yet been assigned. After offsets
     // have been assigned, if the output section uses tail merging, the field
-    // will still have this value and the output section offset is available
-    // from MergeOutputSection<ELFT>::getOffset(). Otherwise, this value has no
-    // special significance, it just means that the offset is 0.
-    PieceLive = uintX_t(0),
+    // will still have this value and the output section offset is computed
+    // lazilly.
+    PieceLive = uintX_t(-2),
   };
 
   std::pair<std::pair<uintX_t, uintX_t> *, uintX_t>




More information about the llvm-commits mailing list