https://github.com/bd1976bris created 
https://github.com/llvm/llvm-project/pull/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

>From b818192de81711e6e5749a030be93430320136fc Mon Sep 17 00:00:00 2001
From: Dunbobbin <ben.dunbob...@sony.com>
Date: Thu, 11 Sep 2025 12:06:44 +0100
Subject: [PATCH] [PS5] Enable support for DTLTO in the PS5 Clang driver

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
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 12 +++++++
 clang/test/Driver/DTLTO/ps5-dtlto.c    | 45 ++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 clang/test/Driver/DTLTO/ps5-dtlto.c

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 21e23d486f9d4..d77f09ce50fff 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -343,6 +343,18 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // whether or not that will be the case at this point. So, unconditionally
   // pass LTO options to ensure proper codegen, metadata production, etc if
   // LTO indeed occurs.
+
+  if (Arg *A = Args.getLastArg(options::OPT_fthinlto_distributor_EQ)) {
+    CmdArgs.push_back(
+        Args.MakeArgString("--thinlto-distributor=" + Twine(A->getValue())));
+    CmdArgs.push_back(
+        Args.MakeArgString("--thinlto-remote-compiler=" +
+                           Twine(D.getClangProgramPath())));
+
+    for (auto A : Args.getAllArgValues(options::OPT_Xthinlto_distributor_EQ))
+      CmdArgs.push_back(Args.MakeArgString("--thinlto-distributor-arg=" + A));
+  }
+
   if (Args.hasFlag(options::OPT_funified_lto, options::OPT_fno_unified_lto,
                    true))
     CmdArgs.push_back(D.getLTOMode() == LTOK_Thin ? "--lto=thin"
diff --git a/clang/test/Driver/DTLTO/ps5-dtlto.c 
b/clang/test/Driver/DTLTO/ps5-dtlto.c
new file mode 100644
index 0000000000000..9b70c88257a85
--- /dev/null
+++ b/clang/test/Driver/DTLTO/ps5-dtlto.c
@@ -0,0 +1,45 @@
+// REQUIRES: lld
+
+/// Check DTLTO options are forwarded to the linker.
+
+/// Check that options are forwarded as expected with --thinlto-distributor=.
+// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
+// RUN:   -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 \
+// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=FORWARD
+
+// FORWARD: prospero-lld
+// FORWARD-SAME: "--thinlto-distributor=d.exe"
+// FORWARD-SAME: "--thinlto-remote-compiler={{[^"]+}}"
+// FORWARD-SAME: "--thinlto-distributor-arg=a1"
+// FORWARD-SAME: "--thinlto-distributor-arg=a2"
+// FORWARD-SAME: "--thinlto-distributor-arg=a3"
+
+/// Check that options are not added without --thinlto-distributor= and
+/// that a warning is issued for unused -Xthinlto-distributor options.
+// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
+// RUN:   -Xthinlto-distributor=a1 -Xthinlto-distributor=a2,a3 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=NODIST --implicit-check-not=distributor \
+// RUN:     --implicit-check-not=remote-compiler
+
+// NODIST: warning: argument unused during compilation: 
'-Xthinlto-distributor=a1'
+// NODIST: warning: argument unused during compilation: 
'-Xthinlto-distributor=a2,a3'
+// NODIST: prospero-lld
+
+/// Check the expected arguments are forwarded by default with only
+/// --thinlto-distributor=.
+// RUN: %clang -flto=thin %s -### --target=x86_64-sie-ps5 \
+// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor 
\
+// RUN:     --implicit-check-not=remote-compiler
+
+// DEFAULT: prospero-lld
+// DEFAULT-SAME: "--thinlto-distributor=d.exe"
+// DEFAULT-SAME: "--thinlto-remote-compiler={{.*}}clang{{[^\"]*}}"
+
+/// Check that the arguments are forwarded unconditionally even when the
+/// compiler is not in LTO mode.
+// RUN: %clang %s -### --target=x86_64-sie-ps5 \
+// RUN:   -fthinlto-distributor=d.exe -Werror 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=DEFAULT --implicit-check-not=distributor 
\
+// RUN:     --implicit-check-not=remote-compiler

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to