From 88e7be2e6b8e9dfbc20094e833b066c58c1ac1bc Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 16 Jun 2018 12:11:34 +0000 Subject: [ELF] Pass callables by function_ref No need to create a heavyweight std::function if it's not stored. No functionality change intended. llvm-svn: 334885 --- lld/ELF/ICF.cpp | 10 +++++----- lld/ELF/MarkLive.cpp | 11 ++++++----- lld/ELF/OutputSections.cpp | 4 ++-- lld/ELF/OutputSections.h | 2 +- lld/ELF/Relocations.cpp | 2 +- lld/ELF/Relocations.h | 2 +- lld/ELF/Writer.cpp | 9 ++++----- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index f708d96c4fc..8a595ce996a 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -114,9 +114,9 @@ private: size_t findBoundary(size_t Begin, size_t End); void forEachClassRange(size_t Begin, size_t End, - std::function Fn); + llvm::function_ref Fn); - void forEachClass(std::function Fn); + void forEachClass(llvm::function_ref Fn); std::vector Sections; @@ -385,7 +385,7 @@ template size_t ICF::findBoundary(size_t Begin, size_t End) { // This function calls Fn on every group within [Begin, End). template void ICF::forEachClassRange(size_t Begin, size_t End, - std::function Fn) { + llvm::function_ref Fn) { while (Begin < End) { size_t Mid = findBoundary(Begin, End); Fn(Begin, Mid); @@ -395,7 +395,7 @@ void ICF::forEachClassRange(size_t Begin, size_t End, // Call Fn on each equivalence class. template -void ICF::forEachClass(std::function Fn) { +void ICF::forEachClass(llvm::function_ref 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 void ICF::run() { // 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(S) | (1 << 31); + S->Class[0] = getHash(S) | (1U << 31); }); // From now on, sections in Sections vector are ordered so that sections diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index bacbf0eee06..a8371e212c3 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -60,8 +60,9 @@ static typename ELFT::uint getAddend(InputSectionBase &Sec, static DenseMap> CNamedSections; template -static void resolveReloc(InputSectionBase &Sec, RelT &Rel, - std::function Fn) { +static void +resolveReloc(InputSectionBase &Sec, RelT &Rel, + llvm::function_ref Fn) { Symbol &B = Sec.getFile()->getRelocTargetSym(Rel); // If a symbol is referenced in a live section, it is used. @@ -90,7 +91,7 @@ static void resolveReloc(InputSectionBase &Sec, RelT &Rel, template static void forEachSuccessor(InputSection &Sec, - std::function Fn) { + llvm::function_ref Fn) { if (Sec.AreRelocsRela) { for (const typename ELFT::Rela &Rel : Sec.template relas()) resolveReloc(Sec, Rel, Fn); @@ -120,7 +121,7 @@ forEachSuccessor(InputSection &Sec, template static void scanEhFrameSection(EhInputSection &EH, ArrayRef Rels, - std::function Fn) { + llvm::function_ref Fn) { const endianness E = ELFT::TargetEndianness; for (unsigned I = 0, N = EH.Pieces.size(); I < N; ++I) { @@ -155,7 +156,7 @@ scanEhFrameSection(EhInputSection &EH, ArrayRef Rels, template static void scanEhFrameSection(EhInputSection &EH, - std::function Fn) { + llvm::function_ref Fn) { if (!EH.NumRelocations) return; diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 31e1d196db4..8253b18b486 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -139,7 +139,7 @@ void OutputSection::addSection(InputSection *IS) { } static void sortByOrder(MutableArrayRef In, - std::function Order) { + llvm::function_ref Order) { typedef std::pair Pair; auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; }; @@ -162,7 +162,7 @@ bool OutputSection::classof(const BaseCommand *C) { return C->Kind == OutputSectionKind; } -void OutputSection::sort(std::function Order) { +void OutputSection::sort(llvm::function_ref Order) { assert(Live); for (BaseCommand *B : SectionCommands) if (auto *ISD = dyn_cast(B)) diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 9720aab0e14..56296f4f2de 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -107,7 +107,7 @@ public: template void writeTo(uint8_t *Buf); template void maybeCompress(); - void sort(std::function Order); + void sort(llvm::function_ref Order); void sortInitFini(); void sortCtorsDtors(); diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 936371303b6..68a97a0a721 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1295,7 +1295,7 @@ std::pair ThunkCreator::getThunk(Symbol &Sym, RelType Type, // InputSectionDescription::Sections. void ThunkCreator::forEachInputSectionDescription( ArrayRef OutputSections, - std::function Fn) { + llvm::function_ref Fn) { for (OutputSection *OS : OutputSections) { if (!(OS->Flags & SHF_ALLOC) || !(OS->Flags & SHF_EXECINSTR)) continue; diff --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h index 3a930d935b0..2a82a677d8a 100644 --- a/lld/ELF/Relocations.h +++ b/lld/ELF/Relocations.h @@ -153,7 +153,7 @@ private: void forEachInputSectionDescription( ArrayRef OutputSections, - std::function Fn); + llvm::function_ref Fn); std::pair getThunk(Symbol &Sym, RelType Type, uint64_t Src); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 0a23d467922..07c981f017b 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -50,7 +50,7 @@ public: private: void copyLocalSymbols(); void addSectionSymbols(); - void forEachRelSec(std::function Fn); + void forEachRelSec(llvm::function_ref 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 void Writer::addRelIpltSymbols() { } template -void Writer::forEachRelSec(std::function Fn) { +void Writer::forEachRelSec( + llvm::function_ref 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 void Writer::resolveShfLinkOrder() { } static void applySynthetic(const std::vector &Sections, - std::function Fn) { + llvm::function_ref Fn) { for (SyntheticSection *SS : Sections) if (SS && SS->getParent() && !SS->empty()) Fn(SS); -- cgit v1.2.3