Commit Diff


commit - 5d5504715671cd3636955b8ebd3cd34495f6646c
commit + e41c3d4bccf9b5cf584f1453e0a028fd066cd926
blob - eae1a4cc3eb565f88b097dd2cc553aabb1c9c777
blob + 05026ece5d8392304533269269a4aa7cf05b48a2
--- gnu/llvm/lld/ELF/Driver.cpp
+++ gnu/llvm/lld/ELF/Driver.cpp
@@ -1405,8 +1405,12 @@ static void readConfigs(opt::InputArgList &args) {
     config->mllvmOpts.emplace_back(arg->getValue());
   }
 
+  config->threadCount = parallel::strategy.compute_thread_count();
+
   // --threads= takes a positive integer and provides the default value for
-  // --thinlto-jobs=.
+  // --thinlto-jobs=. If unspecified, cap the number of threads since
+  // overhead outweighs optimization for used parallel algorithms for the
+  // non-LTO parts.
   if (auto *arg = args.getLastArg(OPT_threads)) {
     StringRef v(arg->getValue());
     unsigned threads = 0;
@@ -1415,10 +1419,12 @@ static void readConfigs(opt::InputArgList &args) {
             arg->getValue() + "'");
     parallel::strategy = hardware_concurrency(threads);
     config->thinLTOJobs = v;
+  } else if (config->threadCount > 4) {
+    log("set maximum concurrency to 4, specify --threads= to change");
+    parallel::strategy = hardware_concurrency(4);
   }
   if (auto *arg = args.getLastArg(OPT_thinlto_jobs_eq))
     config->thinLTOJobs = arg->getValue();
-  config->threadCount = parallel::strategy.compute_thread_count();
 
   if (config->ltoo > 3)
     error("invalid optimization level for LTO: " + Twine(config->ltoo));