diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-12-03 21:24:51 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-12-03 21:24:51 +0000 |
| commit | 244a435ae3ee07ad55576d78b5f5173616d15838 (patch) | |
| tree | 6fa68e7b821e4f2fc18602e57e199425e9d04762 /lld/ELF | |
| parent | 30545b9058824ffcfb14234d299a5f179a5feef7 (diff) | |
| download | bcm5719-llvm-244a435ae3ee07ad55576d78b5f5173616d15838.tar.gz bcm5719-llvm-244a435ae3ee07ad55576d78b5f5173616d15838.zip | |
Factor out common code to a header.
llvm-svn: 288599
Diffstat (limited to 'lld/ELF')
| -rw-r--r-- | lld/ELF/Driver.cpp | 23 | ||||
| -rw-r--r-- | lld/ELF/ICF.cpp | 7 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 7 | ||||
| -rw-r--r-- | lld/ELF/SyntheticSections.cpp | 11 | ||||
| -rw-r--r-- | lld/ELF/Threads.h | 41 |
5 files changed, 59 insertions, 30 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 48e5ad7ede2..d8c486672f2 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -18,9 +18,9 @@ #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" @@ -830,18 +830,15 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { // 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>(); diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp index f2c240995b5..de6e4d3ce16 100644 --- a/lld/ELF/ICF.cpp +++ b/lld/ELF/ICF.cpp @@ -69,8 +69,8 @@ #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" @@ -295,9 +295,8 @@ void ICF<ELFT>::forEachColor(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; - 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); } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 4a723d5667d..cfb8ac9c568 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -16,7 +16,7 @@ #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" @@ -254,10 +254,7 @@ template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) { 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. diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 33515c2f89f..c3888dc83f7 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -24,10 +24,10 @@ #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" @@ -334,14 +334,9 @@ void BuildIdSection<ELFT>::computeHash( 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); diff --git a/lld/ELF/Threads.h b/lld/ELF/Threads.h new file mode 100644 index 00000000000..4103762c7d5 --- /dev/null +++ b/lld/ELF/Threads.h @@ -0,0 +1,41 @@ +//===- 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 |

