[lld] r329242 - Initialize OffsetMap earlier.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 4 17:01:57 PDT 2018


Author: rafael
Date: Wed Apr  4 17:01:57 2018
New Revision: 329242

URL: http://llvm.org/viewvc/llvm-project?rev=329242&view=rev
Log:
Initialize OffsetMap earlier.

Now that getSectionPiece uses OffsetMap, it is advantageous to
initialize it earlier.

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=329242&r1=329241&r2=329242&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Apr  4 17:01:57 2018
@@ -920,6 +920,10 @@ void MergeInputSection::splitIntoPieces(
   else
     splitNonStrings(Data, Entsize);
 
+  OffsetMap.reserve(Pieces.size());
+  for (size_t I = 0, E = Pieces.size(); I != E; ++I)
+    OffsetMap[Pieces[I].InputOff] = I;
+
   if (Config->GcSections && (Flags & SHF_ALLOC))
     for (uint32_t Off : LiveOffsets)
       getSectionPiece(Off)->Live = true;

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=329242&r1=329241&r2=329242&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Apr  4 17:01:57 2018
@@ -2440,15 +2440,10 @@ void MergeTailSection::finalizeContents(
   // finalize() fixed tail-optimized strings, so we can now get
   // offsets of strings. Get an offset for each string and save it
   // to a corresponding StringPiece for easy access.
-  for (MergeInputSection *Sec : Sections) {
-    Sec->OffsetMap.reserve(Sec->Pieces.size());
-    for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) {
-      SectionPiece &P = Sec->Pieces[I];
-      Sec->OffsetMap[P.InputOff] = I;
-      if (P.Live)
-        P.OutputOff = Builder.getOffset(Sec->getData(I));
-    }
-  }
+  for (MergeInputSection *Sec : Sections)
+    for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I)
+      if (Sec->Pieces[I].Live)
+        Sec->Pieces[I].OutputOff = Builder.getOffset(Sec->getData(I));
 }
 
 void MergeNoTailSection::writeTo(uint8_t *Buf) {
@@ -2501,13 +2496,10 @@ void MergeNoTailSection::finalizeContent
   // So far, section pieces have offsets from beginning of shards, but
   // we want offsets from beginning of the whole section. Fix them.
   parallelForEach(Sections, [&](MergeInputSection *Sec) {
-    Sec->OffsetMap.reserve(Sec->Pieces.size());
-    for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) {
-      SectionPiece &P = Sec->Pieces[I];
-      Sec->OffsetMap[P.InputOff] = I;
-      if (P.Live)
-        P.OutputOff += ShardOffsets[getShardId(P.Hash)];
-    }
+    for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I)
+      if (Sec->Pieces[I].Live)
+        Sec->Pieces[I].OutputOff +=
+            ShardOffsets[getShardId(Sec->Pieces[I].Hash)];
   });
 }
 




More information about the llvm-commits mailing list