Skip to content

Commit 36fe827

Browse files
committed
Support more than one LTO partition.
1 parent fec5490 commit 36fe827

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

lld/test/ELF/dtlto/parallel.test

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# REQUIRES: x86
2+
3+
## Test that DTLTO works with more than one LTO partition.
4+
5+
# RUN: rm -rf %t.dir && split-file %s %t.dir && cd %t.dir
6+
7+
# Compile bitcode.
8+
RUN: llvm-as -o full.bc full.ll
9+
RUN: opt -thinlto-bc thin1.ll -o thin1.bc
10+
RUN: opt -thinlto-bc thin2.ll -o thin2.bc
11+
12+
# Generate mock native object files.
13+
RUN: llc thin1.ll --filetype=obj -o thin1.o --relocation-model=pic
14+
RUN: llc thin2.ll --filetype=obj -o thin2.o --relocation-model=pic
15+
16+
# Link with 3 LTO partitions.
17+
RUN: ld.lld full.bc thin1.bc thin2.bc \
18+
RUN: --thinlto-distributor=%python \
19+
RUN: --thinlto-remote-opt-tool=dummy \
20+
RUN: -mllvm=-thinlto-distributor-arg=%llvm_src_root/utils/dtlto/mock.py \
21+
RUN: -mllvm=-thinlto-distributor-arg=thin1.o \
22+
RUN: -mllvm=-thinlto-distributor-arg=thin2.o \
23+
RUN: --save-temps \
24+
RUN: --lto-partitions=3
25+
26+
# DTLTO temporary object files include the task number and a PID component. The
27+
# task number should incorporate the LTO partition number.
28+
RUN: ls | FileCheck %s
29+
CHECK: thin1.3.[[#]].native.o
30+
CHECK: thin2.4.[[#]].native.o
31+
32+
#--- full.ll
33+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
34+
target triple = "x86_64-unknown-linux-gnu"
35+
36+
define void @foo() mustprogress {
37+
call void @bar()
38+
ret void
39+
}
40+
41+
define void @bar() mustprogress {
42+
call void @foo()
43+
ret void
44+
}
45+
46+
#--- thin1.ll
47+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
48+
target triple = "x86_64-unknown-linux-gnu"
49+
50+
define void @baz() {
51+
entry:
52+
ret void
53+
}
54+
55+
#--- thin2.ll
56+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
57+
target triple = "x86_64-unknown-linux-gnu"
58+
59+
define void @_start() {
60+
entry:
61+
ret void
62+
}

llvm/include/llvm/LTO/LTO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class ThinBackendProc {
225225
BackendThreadPool(ThinLTOParallelism) {}
226226

227227
virtual ~ThinBackendProc() = default;
228-
virtual void setup(unsigned MaxTasks) {}
228+
virtual void setup(unsigned MaxTasks, unsigned ReservedTasks) {}
229229
virtual Error start(
230230
unsigned Task, BitcodeModule BM,
231231
const FunctionImporter::ImportMapTy &ImportList,

llvm/lib/LTO/LTO.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,8 @@ Error LTO::runThinLTO(AddStreamFn AddStream, AddBufferFn AddBuffer,
20622062
ResolvedODR[Mod.first], ThinLTO.ModuleMap, ThinLTO.ModuleTriples);
20632063
};
20642064

2065-
BackendProcess->setup(ModuleMap.size());
2065+
BackendProcess->setup(ModuleMap.size(),
2066+
RegularLTO.ParallelCodeGenParallelismLevel);
20662067

20672068
if (BackendProcess->getThreadCount() == 1 ||
20682069
BackendProcess->isSensitiveToInputOrder()) {
@@ -2228,6 +2229,9 @@ class OutOfProcessThinBackend : public CGThinBackend {
22282229
// A unique string to identify the current link.
22292230
SmallString<8> UID;
22302231

2232+
// The first ReservedTasks entries in the task range are used for Full LTO.
2233+
unsigned ReservedTasks;
2234+
22312235
public:
22322236
OutOfProcessThinBackend(
22332237
const Config &Conf, ModuleSummaryIndex &CombinedIndex,
@@ -2244,9 +2248,10 @@ class OutOfProcessThinBackend : public CGThinBackend {
22442248
RemoteOptTool(RemoteOptTool), DistributorPath(Distributor),
22452249
SaveTemps(SaveTemps) {}
22462250

2247-
virtual void setup(unsigned MaxTasks) override {
2251+
virtual void setup(unsigned MaxTasks, unsigned ReservedTasks) override {
22482252
UID = itostr(sys::Process::getProcessId());
22492253
Jobs.resize((size_t)MaxTasks);
2254+
this->ReservedTasks = ReservedTasks;
22502255
}
22512256

22522257
Error start(
@@ -2263,7 +2268,7 @@ class OutOfProcessThinBackend : public CGThinBackend {
22632268
sys::path::append(ObjFilePath, sys::path::stem(ModulePath) + "." +
22642269
itostr(Task) + "." + UID + ".native.o");
22652270

2266-
Job &J = Jobs[Task - 1]; /*Task 0 is reserved*/
2271+
Job &J = Jobs[Task - ReservedTasks];
22672272
J = {Task,
22682273
ModulePath,
22692274
ModuleTriples[ModulePath],

0 commit comments

Comments
 (0)