Skip to content

Commit 050a7a2

Browse files
committed
[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
1 parent 2690d4d commit 050a7a2

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

lld/MachO/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct Configuration {
9898
llvm::StringRef mapFile;
9999
llvm::StringRef outputFile;
100100
llvm::StringRef ltoObjPath;
101+
llvm::StringRef thinLTOJobs;
101102
bool demangle = false;
102103
llvm::MachO::Target target;
103104
PlatformInfo platformInfo;

lld/MachO/Driver.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,12 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
893893
error(arg->getSpelling() + ": expected a positive integer, but got '" +
894894
arg->getValue() + "'");
895895
parallel::strategy = hardware_concurrency(threads);
896-
// FIXME: use this to configure ThinLTO concurrency too
896+
config->thinLTOJobs = v;
897897
}
898+
if (auto *arg = args.getLastArg(OPT_thinlto_jobs_eq))
899+
config->thinLTOJobs = arg->getValue();
900+
if (!get_threadpool_strategy(config->thinLTOJobs))
901+
error("--thinlto-jobs: invalid job count: " + config->thinLTOJobs);
898902

899903
config->entry = symtab->addUndefined(args.getLastArgValue(OPT_e, "_main"),
900904
/*file=*/nullptr,

lld/MachO/LTO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static lto::Config createConfig() {
4343
}
4444

4545
BitcodeCompiler::BitcodeCompiler() {
46-
lto::ThinBackend backend =
47-
lto::createInProcessThinBackend(heavyweight_hardware_concurrency());
46+
lto::ThinBackend backend = lto::createInProcessThinBackend(
47+
heavyweight_hardware_concurrency(config->thinLTOJobs));
4848
ltoObj = std::make_unique<lto::LTO>(createConfig(), backend);
4949
}
5050

lld/MachO/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def color_diagnostics_eq: Joined<["--"], "color-diagnostics=">,
2323
def threads_eq : Joined<["--"], "threads=">,
2424
HelpText<"Number of threads. '1' disables multi-threading. By default all available hardware threads are used">,
2525
Group<grp_lld>;
26+
def thinlto_jobs_eq : Joined<["--"], "thinlto-jobs=">,
27+
HelpText<"Number of ThinLTO jobs. Default to --threads=">,
28+
Group<grp_lld>;
2629
def reproduce: Separate<["--"], "reproduce">,
2730
Group<grp_lld>;
2831
def reproduce_eq: Joined<["--"], "reproduce=">,

lld/test/MachO/thinlto-jobs.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; REQUIRES: x86
2+
; RUN: rm -rf %t; split-file %s %t
3+
4+
;; I'm not aware of a deterministic way to verify whether LTO is running in
5+
;; single- or multi-threaded mode. So this test simply checks that we can parse
6+
;; the --thinlto-jobs flag correctly, but doesn't verify its effect.
7+
8+
; RUN: opt -module-summary %t/f.s -o %t/f.o
9+
; RUN: opt -module-summary %t/g.s -o %t/g.o
10+
11+
; RUN: %lld --time-trace --thinlto-jobs=1 -dylib %t/f.o %t/g.o -o %t/out
12+
; RUN: %lld --time-trace --thinlto-jobs=2 -dylib %t/f.o %t/g.o -o %t/out
13+
; RUN: %lld --thinlto-jobs=all -dylib %t/f.o %t/g.o -o /dev/null
14+
15+
;; Test with a bad value
16+
; RUN: not %lld --thinlto-jobs=foo -dylib %t/f.o %t/g.o -o /dev/null 2>&1 | FileCheck %s
17+
; CHECK: error: --thinlto-jobs: invalid job count: foo
18+
19+
;--- f.s
20+
target triple = "x86_64-apple-darwin"
21+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
22+
23+
declare void @g(...)
24+
25+
define void @f() {
26+
entry:
27+
call void (...) @g()
28+
ret void
29+
}
30+
31+
;--- g.s
32+
target triple = "x86_64-apple-darwin"
33+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
34+
35+
define void @g() {
36+
entry:
37+
ret void
38+
}

0 commit comments

Comments
 (0)