[lld] r299709 - Cache the result of findSection.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 6 14:05:39 PDT 2017


Author: rafael
Date: Thu Apr  6 16:05:39 2017
New Revision: 299709

URL: http://llvm.org/viewvc/llvm-project?rev=299709&view=rev
Log:
Cache the result of findSection.

This avoids calling it multiple times. In particular, we don't have to
call in in assignAddresses any more.

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

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=299709&r1=299708&r2=299709&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Apr  6 16:05:39 2017
@@ -567,7 +567,7 @@ MemoryRegion *LinkerScript::findMemoryRe
 // This function assigns offsets to input sections and an output section
 // for a single sections command (e.g. ".text { *(.text); }").
 void LinkerScript::assignOffsets(OutputSectionCommand *Cmd) {
-  OutputSection *Sec = findSection(Cmd->Name, *OutputSections);
+  OutputSection *Sec = Cmd->Sec;
   if (!Sec)
     return;
 
@@ -614,7 +614,7 @@ void LinkerScript::removeEmptyCommands()
   auto Pos = std::remove_if(
       Opt.Commands.begin(), Opt.Commands.end(), [&](BaseCommand *Base) {
         if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
-          return !findSection(Cmd->Name, *OutputSections);
+          return !Cmd->Sec;
         return false;
       });
   Opt.Commands.erase(Pos, Opt.Commands.end());
@@ -639,6 +639,7 @@ void LinkerScript::adjustSectionsBeforeS
     if (!Cmd)
       continue;
     if (OutputSection *Sec = findSection(Cmd->Name, *OutputSections)) {
+      Cmd->Sec = Sec;
       Flags = Sec->Flags;
       Type = Sec->Type;
       continue;
@@ -649,6 +650,7 @@ void LinkerScript::adjustSectionsBeforeS
 
     auto *OutSec = make<OutputSection>(Cmd->Name, Type, Flags);
     OutputSections->push_back(OutSec);
+    Cmd->Sec = OutSec;
   }
 }
 
@@ -764,7 +766,9 @@ void LinkerScript::placeOrphanSections()
       return Cmd && Cmd->Name == Name;
     });
     if (Pos == E) {
-      Opt.Commands.insert(CmdIter, make<OutputSectionCommand>(Name));
+      auto *Cmd = make<OutputSectionCommand>(Name);
+      Cmd->Sec = Sec;
+      Opt.Commands.insert(CmdIter, Cmd);
       ++CmdIndex;
       continue;
     }

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=299709&r1=299708&r2=299709&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Thu Apr  6 16:05:39 2017
@@ -105,6 +105,7 @@ struct OutputSectionCommand : BaseComman
 
   static bool classof(const BaseCommand *C);
 
+  OutputSection *Sec = nullptr;
   StringRef Name;
   Expr AddrExpr;
   Expr AlignExpr;




More information about the llvm-commits mailing list