[lld] 050a7a2 - [lld-macho] Support --thinlto-jobs

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 09:21:12 PDT 2021


Author: Jez Ng
Date: 2021-04-08T12:21:01-04:00
New Revision: 050a7a27ca844a912e46cdfeed7a472847ad0bc9

URL: https://github.com/llvm/llvm-project/commit/050a7a27ca844a912e46cdfeed7a472847ad0bc9
DIFF: https://github.com/llvm/llvm-project/commit/050a7a27ca844a912e46cdfeed7a472847ad0bc9.diff

LOG: [lld-macho] Support --thinlto-jobs

The test is loosely based off LLD-ELF's `thinlto.ll`. However, I
found that test questionable because the the -save_temps behavior it
checks for is identical regardless of whether we are running in single-
or multi-threaded mode. I tried writing a test based on `--time-trace`
but couldn't get it to run deterministically... so I've opted to just
skip checking that behavior for now.

Reviewed By: #lld-macho, gkm

Differential Revision: https://reviews.llvm.org/D99356

Added: 
    lld/test/MachO/thinlto-jobs.ll

Modified: 
    lld/MachO/Config.h
    lld/MachO/Driver.cpp
    lld/MachO/LTO.cpp
    lld/MachO/Options.td

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 5c9faa8c7328..693c348d9153 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -98,6 +98,7 @@ struct Configuration {
   llvm::StringRef mapFile;
   llvm::StringRef outputFile;
   llvm::StringRef ltoObjPath;
+  llvm::StringRef thinLTOJobs;
   bool demangle = false;
   llvm::MachO::Target target;
   PlatformInfo platformInfo;

diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 736e4566eb4d..7f3415700e33 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -893,8 +893,12 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
       error(arg->getSpelling() + ": expected a positive integer, but got '" +
             arg->getValue() + "'");
     parallel::strategy = hardware_concurrency(threads);
-    // FIXME: use this to configure ThinLTO concurrency too
+    config->thinLTOJobs = v;
   }
+  if (auto *arg = args.getLastArg(OPT_thinlto_jobs_eq))
+    config->thinLTOJobs = arg->getValue();
+  if (!get_threadpool_strategy(config->thinLTOJobs))
+    error("--thinlto-jobs: invalid job count: " + config->thinLTOJobs);
 
   config->entry = symtab->addUndefined(args.getLastArgValue(OPT_e, "_main"),
                                        /*file=*/nullptr,

diff  --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 7b558355610f..70c555f102bb 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -43,8 +43,8 @@ static lto::Config createConfig() {
 }
 
 BitcodeCompiler::BitcodeCompiler() {
-  lto::ThinBackend backend =
-      lto::createInProcessThinBackend(heavyweight_hardware_concurrency());
+  lto::ThinBackend backend = lto::createInProcessThinBackend(
+      heavyweight_hardware_concurrency(config->thinLTOJobs));
   ltoObj = std::make_unique<lto::LTO>(createConfig(), backend);
 }
 

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index 90be9675383b..e4bdc4baa45d 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -23,6 +23,9 @@ def color_diagnostics_eq: Joined<["--"], "color-diagnostics=">,
 def threads_eq : Joined<["--"], "threads=">,
     HelpText<"Number of threads. '1' disables multi-threading. By default all available hardware threads are used">,
     Group<grp_lld>;
+def thinlto_jobs_eq : Joined<["--"], "thinlto-jobs=">,
+    HelpText<"Number of ThinLTO jobs. Default to --threads=">,
+    Group<grp_lld>;
 def reproduce: Separate<["--"], "reproduce">,
     Group<grp_lld>;
 def reproduce_eq: Joined<["--"], "reproduce=">,

diff  --git a/lld/test/MachO/thinlto-jobs.ll b/lld/test/MachO/thinlto-jobs.ll
new file mode 100644
index 000000000000..c35595f5ac66
--- /dev/null
+++ b/lld/test/MachO/thinlto-jobs.ll
@@ -0,0 +1,38 @@
+; REQUIRES: x86
+; RUN: rm -rf %t; split-file %s %t
+
+;; I'm not aware of a deterministic way to verify whether LTO is running in
+;; single- or multi-threaded mode. So this test simply checks that we can parse
+;; the --thinlto-jobs flag correctly, but doesn't verify its effect.
+
+; RUN: opt -module-summary %t/f.s -o %t/f.o
+; RUN: opt -module-summary %t/g.s -o %t/g.o
+
+; RUN: %lld --time-trace --thinlto-jobs=1 -dylib %t/f.o %t/g.o -o %t/out
+; RUN: %lld --time-trace --thinlto-jobs=2 -dylib %t/f.o %t/g.o -o %t/out
+; RUN: %lld --thinlto-jobs=all -dylib %t/f.o %t/g.o -o /dev/null
+
+;; Test with a bad value
+; RUN: not %lld --thinlto-jobs=foo -dylib %t/f.o %t/g.o -o /dev/null 2>&1 | FileCheck %s
+; CHECK: error: --thinlto-jobs: invalid job count: foo
+
+;--- f.s
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+declare void @g(...)
+
+define void @f() {
+entry:
+  call void (...) @g()
+  ret void
+}
+
+;--- g.s
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @g() {
+entry:
+  ret void
+}


        


More information about the llvm-commits mailing list