[lld] r310040 - [ELF] - Replace parallelForEach with ranged form.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 01:30:17 PDT 2017


Author: grimar
Date: Fri Aug  4 01:30:16 2017
New Revision: 310040

URL: http://llvm.org/viewvc/llvm-project?rev=310040&view=rev
Log:
[ELF] - Replace parallelForEach with ranged form.

Makes code a bit more convinent to write/read.

Differential revision: https://reviews.llvm.org/D36089

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/Threads.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=310040&r1=310039&r2=310040&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Aug  4 01:30:16 2017
@@ -2218,15 +2218,14 @@ size_t MergeSyntheticSection::getSize()
 void elf::decompressAndMergeSections() {
   // splitIntoPieces needs to be called on each MergeInputSection before calling
   // finalizeContents(). Do that first.
-  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<MergeInputSection>(S))
-                      MS->splitIntoPieces();
-                  });
+  parallelForEach(InputSections, [](InputSectionBase *S) {
+    if (!S->Live)
+      return;
+    if (Decompressor::isCompressedELFSection(S->Flags, S->Name))
+      S->uncompress();
+    if (auto *MS = dyn_cast<MergeInputSection>(S))
+      MS->splitIntoPieces();
+  });
 
   std::vector<MergeSyntheticSection *> MergeSections;
   for (InputSectionBase *&S : InputSections) {

Modified: lld/trunk/ELF/Threads.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Threads.h?rev=310040&r1=310039&r2=310040&view=diff
==============================================================================
--- lld/trunk/ELF/Threads.h (original)
+++ lld/trunk/ELF/Threads.h Fri Aug  4 01:30:16 2017
@@ -67,12 +67,11 @@
 namespace lld {
 namespace elf {
 
-template <class IterTy, class FuncTy>
-void parallelForEach(IterTy Begin, IterTy End, FuncTy Fn) {
+template <typename R, class FuncTy> void parallelForEach(R &&Range, FuncTy Fn) {
   if (Config->Threads)
-    for_each(llvm::parallel::par, Begin, End, Fn);
+    for_each(llvm::parallel::par, std::begin(Range), std::end(Range), Fn);
   else
-    for_each(llvm::parallel::seq, Begin, End, Fn);
+    for_each(llvm::parallel::seq, std::begin(Range), std::end(Range), Fn);
 }
 
 inline void parallelForEachN(size_t Begin, size_t End,

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=310040&r1=310039&r2=310040&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Aug  4 01:30:16 2017
@@ -199,7 +199,7 @@ template <class ELFT> void Writer<ELFT>:
   // If -compressed-debug-sections is specified, we need to compress
   // .debug_* sections. Do it right now because it changes the size of
   // output sections.
-  parallelForEach(OutputSections.begin(), OutputSections.end(),
+  parallelForEach(OutputSections,
                   [](OutputSection *Sec) { Sec->maybeCompress<ELFT>(); });
 
   Script->assignAddresses();




More information about the llvm-commits mailing list