Rename forEach -> parallelForEach and forLoop -> parallelFor.

"Parallel" is the most important aspect of the functions,
so we shouldn't omit that.

llvm-svn: 298557
This commit is contained in:
Rui Ueyama 2017-03-22 23:03:35 +00:00
parent ca0e7f6472
commit 4995afd943
5 changed files with 20 additions and 16 deletions

View File

@ -942,7 +942,8 @@ template <class ELFT> 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) {
parallelForEach(InputSections.begin(), InputSections.end(),
[](InputSectionBase *S) {
if (!S->Live)
return;
if (Decompressor::isCompressedELFSection(S->Flags, S->Name))

View File

@ -325,8 +325,9 @@ void ICF<ELFT>::forEachClass(std::function<void(size_t, size_t)> 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;
}

View File

@ -238,8 +238,8 @@ template <class ELFT> 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<ELFT>(Buf); };
forEach(Sections.begin(), Sections.end(), Fn);
parallelForEach(Sections.begin(), Sections.end(),
[=](InputSection *IS) { IS->writeTo<ELFT>(Buf); });
// Linker scripts may have BYTE()-family commands with which you
// can write arbitrary bytes to the output. Process them if any.

View File

@ -356,8 +356,9 @@ void BuildIdSection::computeHash(
std::vector<uint8_t> 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);

View File

@ -69,14 +69,15 @@ namespace lld {
namespace elf {
template <class IterTy, class FuncTy>
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<void(size_t)> Fn) {
inline void parallelFor(size_t Begin, size_t End,
std::function<void(size_t)> Fn) {
if (Config->Threads) {
parallel_for(Begin, End, Fn);
} else {