[lld] r334885 - [ELF] Pass callables by function_ref

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 16 05:11:34 PDT 2018


Author: d0k
Date: Sat Jun 16 05:11:34 2018
New Revision: 334885

URL: http://llvm.org/viewvc/llvm-project?rev=334885&view=rev
Log:
[ELF] Pass callables by function_ref

No need to create a heavyweight std::function if it's not stored. No
functionality change intended.

Modified:
    lld/trunk/ELF/ICF.cpp
    lld/trunk/ELF/MarkLive.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Relocations.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=334885&r1=334884&r2=334885&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Sat Jun 16 05:11:34 2018
@@ -114,9 +114,9 @@ private:
   size_t findBoundary(size_t Begin, size_t End);
 
   void forEachClassRange(size_t Begin, size_t End,
-                         std::function<void(size_t, size_t)> Fn);
+                         llvm::function_ref<void(size_t, size_t)> Fn);
 
-  void forEachClass(std::function<void(size_t, size_t)> Fn);
+  void forEachClass(llvm::function_ref<void(size_t, size_t)> Fn);
 
   std::vector<InputSection *> Sections;
 
@@ -385,7 +385,7 @@ template <class ELFT> size_t ICF<ELFT>::
 // This function calls Fn on every group within [Begin, End).
 template <class ELFT>
 void ICF<ELFT>::forEachClassRange(size_t Begin, size_t End,
-                                  std::function<void(size_t, size_t)> Fn) {
+                                  llvm::function_ref<void(size_t, size_t)> Fn) {
   while (Begin < End) {
     size_t Mid = findBoundary(Begin, End);
     Fn(Begin, Mid);
@@ -395,7 +395,7 @@ void ICF<ELFT>::forEachClassRange(size_t
 
 // Call Fn on each equivalence class.
 template <class ELFT>
-void ICF<ELFT>::forEachClass(std::function<void(size_t, size_t)> Fn) {
+void ICF<ELFT>::forEachClass(llvm::function_ref<void(size_t, size_t)> Fn) {
   // If threading is disabled or the number of sections are
   // too small to use threading, call Fn sequentially.
   if (!ThreadsEnabled || Sections.size() < 1024) {
@@ -444,7 +444,7 @@ template <class ELFT> void ICF<ELFT>::ru
   // Initially, we use hash values to partition sections.
   parallelForEach(Sections, [&](InputSection *S) {
     // Set MSB to 1 to avoid collisions with non-hash IDs.
-    S->Class[0] = getHash<ELFT>(S) | (1 << 31);
+    S->Class[0] = getHash<ELFT>(S) | (1U << 31);
   });
 
   // From now on, sections in Sections vector are ordered so that sections

Modified: lld/trunk/ELF/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MarkLive.cpp?rev=334885&r1=334884&r2=334885&view=diff
==============================================================================
--- lld/trunk/ELF/MarkLive.cpp (original)
+++ lld/trunk/ELF/MarkLive.cpp Sat Jun 16 05:11:34 2018
@@ -60,8 +60,9 @@ static typename ELFT::uint getAddend(Inp
 static DenseMap<StringRef, std::vector<InputSectionBase *>> CNamedSections;
 
 template <class ELFT, class RelT>
-static void resolveReloc(InputSectionBase &Sec, RelT &Rel,
-                         std::function<void(InputSectionBase *, uint64_t)> Fn) {
+static void
+resolveReloc(InputSectionBase &Sec, RelT &Rel,
+             llvm::function_ref<void(InputSectionBase *, uint64_t)> Fn) {
   Symbol &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
 
   // If a symbol is referenced in a live section, it is used.
@@ -90,7 +91,7 @@ static void resolveReloc(InputSectionBas
 template <class ELFT>
 static void
 forEachSuccessor(InputSection &Sec,
-                 std::function<void(InputSectionBase *, uint64_t)> Fn) {
+                 llvm::function_ref<void(InputSectionBase *, uint64_t)> Fn) {
   if (Sec.AreRelocsRela) {
     for (const typename ELFT::Rela &Rel : Sec.template relas<ELFT>())
       resolveReloc<ELFT>(Sec, Rel, Fn);
@@ -120,7 +121,7 @@ forEachSuccessor(InputSection &Sec,
 template <class ELFT, class RelTy>
 static void
 scanEhFrameSection(EhInputSection &EH, ArrayRef<RelTy> Rels,
-                   std::function<void(InputSectionBase *, uint64_t)> Fn) {
+                   llvm::function_ref<void(InputSectionBase *, uint64_t)> Fn) {
   const endianness E = ELFT::TargetEndianness;
 
   for (unsigned I = 0, N = EH.Pieces.size(); I < N; ++I) {
@@ -155,7 +156,7 @@ scanEhFrameSection(EhInputSection &EH, A
 template <class ELFT>
 static void
 scanEhFrameSection(EhInputSection &EH,
-                   std::function<void(InputSectionBase *, uint64_t)> Fn) {
+                   llvm::function_ref<void(InputSectionBase *, uint64_t)> Fn) {
   if (!EH.NumRelocations)
     return;
 

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=334885&r1=334884&r2=334885&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Sat Jun 16 05:11:34 2018
@@ -139,7 +139,7 @@ void OutputSection::addSection(InputSect
 }
 
 static void sortByOrder(MutableArrayRef<InputSection *> In,
-                        std::function<int(InputSectionBase *S)> Order) {
+                        llvm::function_ref<int(InputSectionBase *S)> Order) {
   typedef std::pair<int, InputSection *> Pair;
   auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; };
 
@@ -162,7 +162,7 @@ bool OutputSection::classof(const BaseCo
   return C->Kind == OutputSectionKind;
 }
 
-void OutputSection::sort(std::function<int(InputSectionBase *S)> Order) {
+void OutputSection::sort(llvm::function_ref<int(InputSectionBase *S)> Order) {
   assert(Live);
   for (BaseCommand *B : SectionCommands)
     if (auto *ISD = dyn_cast<InputSectionDescription>(B))

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=334885&r1=334884&r2=334885&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Sat Jun 16 05:11:34 2018
@@ -107,7 +107,7 @@ public:
   template <class ELFT> void writeTo(uint8_t *Buf);
   template <class ELFT> void maybeCompress();
 
-  void sort(std::function<int(InputSectionBase *S)> Order);
+  void sort(llvm::function_ref<int(InputSectionBase *S)> Order);
   void sortInitFini();
   void sortCtorsDtors();
 

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=334885&r1=334884&r2=334885&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sat Jun 16 05:11:34 2018
@@ -1295,7 +1295,7 @@ std::pair<Thunk *, bool> ThunkCreator::g
 // InputSectionDescription::Sections.
 void ThunkCreator::forEachInputSectionDescription(
     ArrayRef<OutputSection *> OutputSections,
-    std::function<void(OutputSection *, InputSectionDescription *)> Fn) {
+    llvm::function_ref<void(OutputSection *, InputSectionDescription *)> Fn) {
   for (OutputSection *OS : OutputSections) {
     if (!(OS->Flags & SHF_ALLOC) || !(OS->Flags & SHF_EXECINSTR))
       continue;

Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=334885&r1=334884&r2=334885&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Sat Jun 16 05:11:34 2018
@@ -153,7 +153,7 @@ private:
 
   void forEachInputSectionDescription(
       ArrayRef<OutputSection *> OutputSections,
-      std::function<void(OutputSection *, InputSectionDescription *)> Fn);
+      llvm::function_ref<void(OutputSection *, InputSectionDescription *)> Fn);
 
   std::pair<Thunk *, bool> getThunk(Symbol &Sym, RelType Type, uint64_t Src);
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=334885&r1=334884&r2=334885&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Jun 16 05:11:34 2018
@@ -50,7 +50,7 @@ public:
 private:
   void copyLocalSymbols();
   void addSectionSymbols();
-  void forEachRelSec(std::function<void(InputSectionBase &)> Fn);
+  void forEachRelSec(llvm::function_ref<void(InputSectionBase &)> Fn);
   void sortSections();
   void resolveShfLinkOrder();
   void sortInputSections();
@@ -83,8 +83,6 @@ private:
 
   uint64_t FileSize;
   uint64_t SectionHeaderOff;
-
-  bool HasGotBaseSym = false;
 };
 } // anonymous namespace
 
@@ -889,7 +887,8 @@ template <class ELFT> void Writer<ELFT>:
 }
 
 template <class ELFT>
-void Writer<ELFT>::forEachRelSec(std::function<void(InputSectionBase &)> Fn) {
+void Writer<ELFT>::forEachRelSec(
+    llvm::function_ref<void(InputSectionBase &)> Fn) {
   // Scan all relocations. Each relocation goes through a series
   // of tests to determine if it needs special treatment, such as
   // creating GOT, PLT, copy relocations, etc.
@@ -1474,7 +1473,7 @@ template <class ELFT> void Writer<ELFT>:
 }
 
 static void applySynthetic(const std::vector<SyntheticSection *> &Sections,
-                           std::function<void(SyntheticSection *)> Fn) {
+                           llvm::function_ref<void(SyntheticSection *)> Fn) {
   for (SyntheticSection *SS : Sections)
     if (SS && SS->getParent() && !SS->empty())
       Fn(SS);




More information about the llvm-commits mailing list