Skip to content

Commit 6ae9fcd

Browse files
authored
[PS5] Enable support for DTLTO in the PS5 Clang driver (#158041)
DTLTO support was added for most targets via the shared `addLTOOptions` helper. The PS5 driver does not call that helper, so it did not inherit the feature. Implement the equivalent DTLTO handling in the PS5 driver. Unlike other drivers, we add LTO-related options unconditionally. This makes sense because the linker decides whether to perform LTO based on input file types, not the presence of `-flto` on the compiler command line. Other drivers only add these options when `-flto` is specified. Internal-Ref: TOOLCHAIN-19896
1 parent a0a82ee commit 6ae9fcd

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,18 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
343343
// whether or not that will be the case at this point. So, unconditionally
344344
// pass LTO options to ensure proper codegen, metadata production, etc if
345345
// LTO indeed occurs.
346+
347+
if (const Arg *A = Args.getLastArg(options::OPT_fthinlto_distributor_EQ)) {
348+
CmdArgs.push_back(
349+
Args.MakeArgString("--thinlto-distributor=" + Twine(A->getValue())));
350+
CmdArgs.push_back(Args.MakeArgString("--thinlto-remote-compiler=" +
351+
Twine(D.getClangProgramPath())));
352+
353+
for (const auto &A :
354+
Args.getAllArgValues(options::OPT_Xthinlto_distributor_EQ))
355+
CmdArgs.push_back(Args.MakeArgString("--thinlto-distributor-arg=" + A));
356+
}
357+
346358
if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
347359
true))
348360
CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// REQUIRES: lld
2+
3+
/// Check DTLTO options are forwarded to the linker.
4+
5+
/// Check that options are forwarded as expected with --thinlto-distributor=.
6+
// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
7+
// RUN: -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 \
8+
// RUN: -fthinlto-distributor=d.exe -Werror 2>&1 | \
9+
// RUN: FileCheck %s --check-prefix=FORWARD
10+
11+
// FORWARD: prospero-lld
12+
// FORWARD-SAME: "--thinlto-distributor=d.exe"
13+
// FORWARD-SAME: "--thinlto-remote-compiler={{[^"]+}}"
14+
// FORWARD-SAME: "--thinlto-distributor-arg=a1"
15+
// FORWARD-SAME: "--thinlto-distributor-arg=a2"
16+
// FORWARD-SAME: "--thinlto-distributor-arg=a3"
17+
18+
/// Check that options are not added without --thinlto-distributor= and
19+
/// that a warning is issued for unused -Xthinlto-distributor options.
20+
// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
21+
// RUN: -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 2>&1 | \
22+
// RUN: FileCheck %s --check-prefix=NODIST --implicit-check-not=distributor \
23+
// RUN: --implicit-check-not=remote-compiler
24+
25+
// NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a1'
26+
// NODIST: warning: argument unused during compilation: '-Xthinlto-distributor=a2,a3'
27+
// NODIST: prospero-lld
28+
29+
/// Check the expected arguments are forwarded by default with only
30+
/// --thinlto-distributor=.
31+
// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
32+
// RUN: -fthinlto-distributor=d.exe -Werror 2>&1 | \
33+
// RUN: FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor \
34+
// RUN: --implicit-check-not=remote-compiler
35+
36+
// DEFAULT: prospero-lld
37+
// DEFAULT-SAME: "--thinlto-distributor=d.exe"
38+
// DEFAULT-SAME: "--thinlto-remote-compiler={{.*}}clang{{[^\"]*}}"
39+
40+
/// Check that the arguments are forwarded unconditionally even when the
41+
/// compiler is not in LTO mode.
42+
// RUN: %clang %s -### --target=x86_64-sie-ps5 \
43+
// RUN: -fthinlto-distributor=d.exe -Werror 2>&1 | \
44+
// RUN: FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor \
45+
// RUN: --implicit-check-not=remote-compiler

0 commit comments

Comments
 (0)