#include "Strings.h"
#include "SymbolTable.h"
#include "Target.h"
+#include "Threads.h"
#include "Writer.h"
#include "lld/Config/Version.h"
-#include "lld/Core/Parallel.h"
#include "lld/Driver/Driver.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
// MergeInputSection::splitIntoPieces needs to be called before
// any call of MergeInputSection::getOffset. Do that.
- auto Fn = [](InputSectionBase<ELFT> *S) {
- if (!S->Live)
- return;
- if (S->Compressed)
- S->uncompress();
- if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(S))
- MS->splitIntoPieces();
- };
- if (Config->Threads)
- parallel_for_each(Symtab.Sections.begin(), Symtab.Sections.end(), Fn);
- else
- std::for_each(Symtab.Sections.begin(), Symtab.Sections.end(), Fn);
+ forEach(Symtab.Sections.begin(), Symtab.Sections.end(),
+ [](InputSectionBase<ELFT> *S) {
+ if (!S->Live)
+ return;
+ if (S->Compressed)
+ S->uncompress();
+ if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(S))
+ MS->splitIntoPieces();
+ });
// Write the result to the file.
writeResult<ELFT>();
#include "ICF.h"
#include "Config.h"
#include "SymbolTable.h"
+#include "Threads.h"
-#include "lld/Core/Parallel.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/ELF.h"
// Split sections into 256 shards and call Fn in parallel.
size_t NumShards = 256;
size_t Step = Sections.size() / NumShards;
- parallel_for(size_t(0), NumShards, [&](size_t I) {
- forEachColorRange(I * Step, (I + 1) * Step, Fn);
- });
+ forLoop(0, NumShards,
+ [&](size_t I) { forEachColorRange(I * Step, (I + 1) * Step, Fn); });
forEachColorRange(Step * NumShards, Sections.size(), Fn);
}
#include "SymbolTable.h"
#include "SyntheticSections.h"
#include "Target.h"
-#include "lld/Core/Parallel.h"
+#include "Threads.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MathExtras.h"
fill(Buf, this->Size, Filler);
auto Fn = [=](InputSection<ELFT> *IS) { IS->writeTo(Buf); };
- if (Config->Threads)
- parallel_for_each(Sections.begin(), Sections.end(), Fn);
- else
- std::for_each(Sections.begin(), Sections.end(), Fn);
+ forEach(Sections.begin(), Sections.end(), Fn);
// Linker scripts may have BYTE()-family commands with which you
// can write arbitrary bytes to the output. Process them if any.
#include "Strings.h"
#include "SymbolTable.h"
#include "Target.h"
+#include "Threads.h"
#include "Writer.h"
#include "lld/Config/Version.h"
-#include "lld/Core/Parallel.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/MD5.h"
std::vector<ArrayRef<uint8_t>> Chunks = split(Data, 1024 * 1024);
std::vector<uint8_t> Hashes(Chunks.size() * HashSize);
- auto Fn = [&](size_t I) { HashFn(Hashes.data() + I * HashSize, Chunks[I]); };
-
// Compute hash values.
- if (Config->Threads)
- parallel_for(size_t(0), Chunks.size(), Fn);
- else
- for (size_t I = 0, E = Chunks.size(); I != E; ++I)
- Fn(I);
+ forLoop(0, Chunks.size(),
+ [&](size_t I) { HashFn(Hashes.data() + I * HashSize, Chunks[I]); });
// Write to the final output buffer.
HashFn(HashBuf, Hashes);
--- /dev/null
+//===- Threads.h ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_ELF_THREADS_H
+#define LLD_ELF_THREADS_H
+
+#include "Config.h"
+
+#include "lld/Core/Parallel.h"
+#include <algorithm>
+#include <functional>
+
+namespace lld {
+namespace elf {
+
+template <class IterTy, class FuncTy>
+void forEach(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) {
+ if (Config->Threads) {
+ parallel_for(Begin, End, Fn);
+ } else {
+ for (size_t I = Begin; I < End; ++I)
+ Fn(I);
+ }
+}
+}
+}
+
+#endif