[PATCH] D60495: Load balancing for LTO

David Callahan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 19:32:49 PDT 2019


david2050 created this revision.
Herald added subscribers: llvm-commits, dang, dexonsmith, steven_wu, mgrang, inglorion, mehdi_amini.
Herald added a project: LLVM.

Use bitcode size as an estimated for compilation time and sort
compilation tasks in order decreasing sizee to provide better
load balance when there are large number of taks.


Repository:
  rL LLVM

https://reviews.llvm.org/D60495

Files:
  lib/LTO/LTO.cpp


Index: lib/LTO/LTO.cpp
===================================================================
--- lib/LTO/LTO.cpp
+++ lib/LTO/LTO.cpp
@@ -1295,15 +1295,33 @@
       ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
                       AddStream, Cache);
 
-  // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for combined
-  // module and parallel code generation partitions.
+  // Task numbers start at ParallelCodeGenParallelismLevel if an LTO
+  // module is present, as tasks 0 through ParallelCodeGenParallelismLevel-1
+  // are reserved for parallel code generation partitions.
   unsigned Task = RegularLTO.ParallelCodeGenParallelismLevel;
-  for (auto &Mod : ThinLTO.ModuleMap) {
+
+  // Use buffer size as a proxy for expected compile time and sorted
+  // modules in terms of decreasing size to provide better compile-time
+  // load-balance.
+  using ModuleMapElt = std::pair<StringRef, BitcodeModule>;
+  using ModuleVecElt = std::pair<unsigned, const ModuleMapElt *>;
+  std::vector<ModuleVecElt> ModulesSortedBySize;
+  ModulesSortedBySize.reserve(ThinLTO.ModuleMap.size());
+  for (auto &Mod : ThinLTO.ModuleMap)
+    ModulesSortedBySize.emplace_back(Task++, &Mod);
+  std::sort(ModulesSortedBySize.begin(), ModulesSortedBySize.end(),
+            [](const ModuleVecElt &Left, const ModuleVecElt &Right) {
+              return Left.second->second.getBuffer().size() >
+                     Right.second->second.getBuffer().size();
+            });
+
+  for (auto Pair : ModulesSortedBySize) {
+    unsigned Task = Pair.first;
+    const ModuleMapElt &Mod = *Pair.second;
     if (Error E = BackendProc->start(Task, Mod.second, ImportLists[Mod.first],
                                      ExportLists[Mod.first],
                                      ResolvedODR[Mod.first], ThinLTO.ModuleMap))
       return E;
-    ++Task;
   }
 
   return BackendProc->wait();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60495.194439.patch
Type: text/x-patch
Size: 1918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190410/c6b4795f/attachment.bin>


More information about the llvm-commits mailing list