[lld] r283357 - Compact SectionPiece.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 5 11:40:01 PDT 2016


Author: rafael
Date: Wed Oct  5 13:40:00 2016
New Revision: 283357

URL: http://llvm.org/viewvc/llvm-project?rev=283357&view=rev
Log:
Compact SectionPiece.

It is pretty easy to get the data from the InputSection, so we don't
have to store it.

This opens the way for storing the hash instead.

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=283357&r1=283356&r2=283357&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Oct  5 13:40:00 2016
@@ -28,6 +28,10 @@ using namespace llvm::support::endian;
 using namespace lld;
 using namespace lld::elf;
 
+ArrayRef<uint8_t> InputSectionData::getData(const SectionPiece &P) const {
+  return Data.slice(P.InputOff, P.size());
+}
+
 template <class ELFT>
 static ArrayRef<uint8_t> getSectionContents(elf::ObjectFile<ELFT> *File,
                                             const typename ELFT::Shdr *Hdr) {
@@ -638,7 +642,7 @@ template <class ELFT> void  MergeInputSe
     if (Piece.OutputOff == size_t(-1)) {
       // Offsets of tail-merged strings are computed lazily.
       auto *OutSec = static_cast<MergeOutputSection<ELFT> *>(this->OutSec);
-      ArrayRef<uint8_t> D = Piece.data();
+      ArrayRef<uint8_t> D = this->getData(Piece);
       StringRef S((const char *)D.data(), D.size());
       Piece.OutputOff = OutSec->getOffset(S);
     }

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=283357&r1=283356&r2=283357&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Oct  5 13:40:00 2016
@@ -23,6 +23,7 @@ namespace elf {
 
 class DefinedCommon;
 class SymbolBody;
+struct SectionPiece;
 
 template <class ELFT> class ICF;
 template <class ELFT> class DefinedRegular;
@@ -63,6 +64,7 @@ public:
   StringRef Name;
 
   ArrayRef<uint8_t> Data;
+  ArrayRef<uint8_t> getData(const SectionPiece &P) const;
 
   // If a section is compressed, this has the uncompressed section data.
   std::unique_ptr<char[]> UncompressedData;
@@ -123,10 +125,8 @@ template <class ELFT> InputSectionBase<E
 // SectionPiece represents a piece of splittable section contents.
 struct SectionPiece {
   SectionPiece(size_t Off, ArrayRef<uint8_t> Data, bool Live = false)
-      : InputOff(Off), Data((const uint8_t *)Data.data()), Size(Data.size()),
-        Live(Live || !Config->GcSections) {}
+      : InputOff(Off), Size(Data.size()), Live(Live || !Config->GcSections) {}
 
-  ArrayRef<uint8_t> data() { return {Data, Size}; }
   size_t size() const { return Size; }
 
   size_t InputOff;
@@ -136,7 +136,6 @@ private:
   // We use bitfields because SplitInputSection is accessed by
   // std::upper_bound very often.
   // We want to save bits to make it cache friendly.
-  const uint8_t *Data;
   uint32_t Size : 31;
 
 public:
@@ -182,7 +181,10 @@ private:
 
 struct EhSectionPiece : public SectionPiece {
   EhSectionPiece(size_t Off, ArrayRef<uint8_t> Data, unsigned FirstRelocation)
-      : SectionPiece(Off, Data), FirstRelocation(FirstRelocation) {}
+      : SectionPiece(Off, Data), Data(Data.data()),
+        FirstRelocation(FirstRelocation) {}
+  const uint8_t *Data;
+  ArrayRef<uint8_t> data() { return {Data, size()}; }
   unsigned FirstRelocation;
 };
 

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=283357&r1=283356&r2=283357&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Oct  5 13:40:00 2016
@@ -1191,7 +1191,7 @@ template <class ELFT> void EhOutputSecti
     size_t CieOffset = Cie->Piece->OutputOff;
     writeCieFde<ELFT>(Buf + CieOffset, Cie->Piece->data());
 
-    for (SectionPiece *Fde : Cie->FdePieces) {
+    for (EhSectionPiece *Fde : Cie->FdePieces) {
       size_t Off = Fde->OutputOff;
       writeCieFde<ELFT>(Buf + Off, Fde->data());
 
@@ -1244,7 +1244,7 @@ void MergeOutputSection<ELFT>::addSectio
   for (SectionPiece &Piece : Sec->Pieces) {
     if (!Piece.Live)
       continue;
-    uintX_t OutputOffset = Builder.add(toStringRef(Piece.data()));
+    uintX_t OutputOffset = Builder.add(toStringRef(Sec->getData(Piece)));
     if (!shouldTailMerge())
       Piece.OutputOff = OutputOffset;
   }




More information about the llvm-commits mailing list