[lld] r320654 - Move Repl to SectionBase.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 14:59:23 PST 2017


Author: rafael
Date: Wed Dec 13 14:59:23 2017
New Revision: 320654

URL: http://llvm.org/viewvc/llvm-project?rev=320654&view=rev
Log:
Move Repl to SectionBase.

It is currently in InputSectionBase. Only InputSections are used in
ICF, so Repl should be move to InputSection to clear the class
hierarchy or, like this patch does, to SectionBase for convenience.

The convenience of having it on the base class is that we can just
access the replacement without having to first check if it is an
InputSection. It is a bit less code and a bit faster as some of this
code is very hot.

I got up to 1.77% improvement in clang-gdb-index and no regressions
according to lnt.

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=320654&r1=320653&r2=320654&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Dec 13 14:59:23 2017
@@ -87,7 +87,7 @@ InputSectionBase::InputSectionBase(Input
                                    StringRef Name, Kind SectionKind)
     : SectionBase(SectionKind, Name, Flags, Entsize, Alignment, Type, Info,
                   Link),
-      File(File), Data(Data), Repl(this) {
+      File(File), Data(Data) {
   NumRelocations = 0;
   AreRelocsRela = false;
 

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=320654&r1=320653&r2=320654&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Dec 13 14:59:23 2017
@@ -45,6 +45,13 @@ public:
 
   StringRef Name;
 
+  // This pointer points to the "real" instance of this instance.
+  // Usually Repl == this. However, if ICF merges two sections,
+  // Repl pointer of one section points to another section. So,
+  // if you need to get a pointer to this instance, do not use
+  // this but instead this->Repl.
+  SectionBase *Repl;
+
   unsigned SectionKind : 3;
 
   // The next two bit fields are only used by InputSectionBase, but we
@@ -77,9 +84,9 @@ protected:
   SectionBase(Kind SectionKind, StringRef Name, uint64_t Flags,
               uint64_t Entsize, uint64_t Alignment, uint32_t Type,
               uint32_t Info, uint32_t Link)
-      : Name(Name), SectionKind(SectionKind), Live(false), Bss(false),
-        Alignment(Alignment), Flags(Flags), Entsize(Entsize), Type(Type),
-        Link(Link), Info(Info) {}
+      : Name(Name), Repl(this), SectionKind(SectionKind), Live(false),
+        Bss(false), Alignment(Alignment), Flags(Flags), Entsize(Entsize),
+        Type(Type), Link(Link), Info(Info) {}
 };
 
 // This corresponds to a section of an input file.
@@ -146,13 +153,6 @@ public:
         NumRelocations);
   }
 
-  // This pointer points to the "real" instance of this instance.
-  // Usually Repl == this. However, if ICF merges two sections,
-  // Repl pointer of one section points to another section. So,
-  // if you need to get a pointer to this instance, do not use
-  // this but instead this->Repl.
-  InputSectionBase *Repl;
-
   // InputSections that are dependent on us (reverse dependency for GC)
   llvm::TinyPtrVector<InputSection *> DependentSections;
 

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=320654&r1=320653&r2=320654&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Dec 13 14:59:23 2017
@@ -45,8 +45,6 @@ static uint64_t getSymVA(const Symbol &S
   case Symbol::DefinedKind: {
     auto &D = cast<Defined>(Sym);
     SectionBase *IS = D.Section;
-    if (auto *ISB = dyn_cast_or_null<InputSectionBase>(IS))
-      IS = ISB->Repl;
 
     // According to the ELF spec reference to a local symbol from outside
     // the group are not allowed. Unfortunately .eh_frame breaks that rule
@@ -59,6 +57,7 @@ static uint64_t getSymVA(const Symbol &S
     if (!IS)
       return D.Value;
 
+    IS = IS->Repl;
     uint64_t Offset = D.Value;
 
     // An object in an SHF_MERGE section might be referenced via a
@@ -161,11 +160,8 @@ uint64_t Symbol::getSize() const {
 
 OutputSection *Symbol::getOutputSection() const {
   if (auto *S = dyn_cast<Defined>(this)) {
-    if (auto *Sec = S->Section) {
-      if (auto *IS = dyn_cast<InputSection>(Sec))
-        Sec = IS->Repl;
-      return Sec->getOutputSection();
-    }
+    if (auto *Sec = S->Section)
+      return Sec->Repl->getOutputSection();
     return nullptr;
   }
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=320654&r1=320653&r2=320654&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Dec 13 14:59:23 2017
@@ -516,13 +516,10 @@ static bool includeInSymtab(const Symbol
     SectionBase *Sec = D->Section;
     if (!Sec)
       return true;
-    if (auto *IS = dyn_cast<InputSectionBase>(Sec)) {
-      Sec = IS->Repl;
-      IS = cast<InputSectionBase>(Sec);
-      // Exclude symbols pointing to garbage-collected sections.
-      if (!IS->Live)
-        return false;
-    }
+    Sec = Sec->Repl;
+    // Exclude symbols pointing to garbage-collected sections.
+    if (isa<InputSectionBase>(Sec) && !Sec->Live)
+      return false;
     if (auto *S = dyn_cast<MergeInputSection>(Sec))
       if (!S->getSectionPiece(D->Value)->Live)
         return false;




More information about the llvm-commits mailing list