[PATCH] D36089: [ELF] - Replace parallelForEach with ranged form.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 07:17:12 PDT 2017


grimar created this revision.
Herald added a subscriber: emaste.

Makes code a bit more convinent to write/read.


https://reviews.llvm.org/D36089

Files:
  ELF/SyntheticSections.cpp
  ELF/Threads.h
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -198,7 +198,7 @@
   // 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();
Index: ELF/Threads.h
===================================================================
--- ELF/Threads.h
+++ ELF/Threads.h
@@ -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> auto 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,
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -2217,15 +2217,14 @@
 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36089.108921.patch
Type: text/x-patch
Size: 2394 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170731/1b42fbd6/attachment.bin>


More information about the llvm-commits mailing list