From 4995afd94339629fa2124a93979df1861d37ec2a Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 22 Mar 2017 23:03:35 +0000 Subject: [PATCH] Rename forEach -> parallelForEach and forLoop -> parallelFor. "Parallel" is the most important aspect of the functions, so we shouldn't omit that. llvm-svn: 298557 --- lld/ELF/Driver.cpp | 17 +++++++++-------- lld/ELF/ICF.cpp | 5 +++-- lld/ELF/OutputSections.cpp | 4 ++-- lld/ELF/SyntheticSections.cpp | 5 +++-- lld/ELF/Threads.h | 5 +++-- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 470325f41618..59258ce8edb3 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -942,14 +942,15 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // MergeInputSection::splitIntoPieces needs to be called before // any call of MergeInputSection::getOffset. Do that. - forEach(InputSections.begin(), InputSections.end(), [](InputSectionBase *S) { - if (!S->Live) - return; - if (Decompressor::isCompressedELFSection(S->Flags, S->Name)) - S->uncompress(); - if (auto *MS = dyn_cast(S)) - MS->splitIntoPieces(); - }); + parallelForEach(InputSections.begin(), InputSections.end(), + [](InputSectionBase *S) { + if (!S->Live) + return; + if (Decompressor::isCompressedELFSection(S->Flags, S->Name)) + S->uncompress(); + if (auto *MS = dyn_cast(S)) + MS->splitIntoPieces(); + }); // Write the result to the file. writeResult(); diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index 233b866cdc14..a9de0fc71eb6 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -325,8 +325,9 @@ void ICF::forEachClass(std::function Fn) { // Split sections into 256 shards and call Fn in parallel. size_t NumShards = 256; size_t Step = Sections.size() / NumShards; - forLoop(0, NumShards, - [&](size_t I) { forEachClassRange(I * Step, (I + 1) * Step, Fn); }); + parallelFor(0, NumShards, [&](size_t I) { + forEachClassRange(I * Step, (I + 1) * Step, Fn); + }); forEachClassRange(Step * NumShards, Sections.size(), Fn); ++Cnt; } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index c159669fbab2..cda8a2b3f422 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -238,8 +238,8 @@ template void OutputSection::writeTo(uint8_t *Buf) { if (uint32_t Filler = Script->getFiller(this->Name)) fill(Buf, this->Size, Filler); - auto Fn = [=](InputSection *IS) { IS->writeTo(Buf); }; - forEach(Sections.begin(), Sections.end(), Fn); + parallelForEach(Sections.begin(), Sections.end(), + [=](InputSection *IS) { IS->writeTo(Buf); }); // Linker scripts may have BYTE()-family commands with which you // can write arbitrary bytes to the output. Process them if any. diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index c98f152e29fb..22c7f2689957 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -356,8 +356,9 @@ void BuildIdSection::computeHash( std::vector Hashes(Chunks.size() * HashSize); // Compute hash values. - forLoop(0, Chunks.size(), - [&](size_t I) { HashFn(Hashes.data() + I * HashSize, Chunks[I]); }); + parallelFor(0, Chunks.size(), [&](size_t I) { + HashFn(Hashes.data() + I * HashSize, Chunks[I]); + }); // Write to the final output buffer. HashFn(HashBuf, Hashes); diff --git a/lld/ELF/Threads.h b/lld/ELF/Threads.h index c03e15253e15..3df9636068a2 100644 --- a/lld/ELF/Threads.h +++ b/lld/ELF/Threads.h @@ -69,14 +69,15 @@ namespace lld { namespace elf { template -void forEach(IterTy Begin, IterTy End, FuncTy Fn) { +void parallelForEach(IterTy Begin, IterTy End, FuncTy Fn) { if (Config->Threads) parallel_for_each(Begin, End, Fn); else std::for_each(Begin, End, Fn); } -inline void forLoop(size_t Begin, size_t End, std::function Fn) { +inline void parallelFor(size_t Begin, size_t End, + std::function Fn) { if (Config->Threads) { parallel_for(Begin, End, Fn); } else { -- GitLab