[PATCH] D126800: Write output sections in parallel

Michael Eisel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 1 14:07:13 PDT 2022


michaeleisel updated this revision to Diff 433541.
michaeleisel added a comment.

Use range-based insertion for output sections


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126800/new/

https://reviews.llvm.org/D126800

Files:
  lld/MachO/Writer.cpp


Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -20,6 +20,7 @@
 #include "SyntheticSections.h"
 #include "Target.h"
 #include "UnwindInfoSection.h"
+#include "llvm/Support/Parallel.h"
 
 #include "lld/Common/Arrays.h"
 #include "lld/Common/CommonLinkerContext.h"
@@ -1081,9 +1082,15 @@
 
 void Writer::writeSections() {
   uint8_t *buf = buffer->getBufferStart();
-  for (const OutputSegment *seg : outputSegments)
-    for (const OutputSection *osec : seg->getSections())
-      osec->writeTo(buf + osec->fileOff);
+  std::vector<const OutputSection *> osecs;
+  for (const OutputSegment *seg : outputSegments) {
+    const std::vector<OutputSection *> &sections = seg->getSections();
+    osecs.insert(osecs.end(), sections.begin(), sections.end());
+  }
+
+  parallelForEach(osecs.begin(), osecs.end(), [&](const OutputSection *osec) {
+    osec->writeTo(buf + osec->fileOff);
+  });
 }
 
 // In order to utilize multiple cores, we first split the buffer into chunks,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126800.433541.patch
Type: text/x-patch
Size: 1072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220601/0068a80f/attachment.bin>


More information about the llvm-commits mailing list