[clang] [HIP] Fix `-flto` overriding `--no-lto` not that it is default (PR #202699)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 9 08:54:41 PDT 2026
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/202699
Summary:
The previous changes to LTO made the flto flag passed by default which
overrode the hack we did to ervert to the old non-LTO pipline. This is a
temporary hack so I'm hacking it even further to fix it.
>From 53dde9652e2e416feb997f445c7480327cc0f55f Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 9 Jun 2026 10:53:33 -0500
Subject: [PATCH] [HIP] Fix `-flto` overriding `--no-lto` not that it is
default
Summary:
The previous changes to LTO made the flto flag passed by default which
overrode the hack we did to ervert to the old non-LTO pipline. This is a
temporary hack so I'm hacking it even further to fix it.
---
.../clang-linker-wrapper/ClangLinkerWrapper.cpp | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 6e4fc7060389c..cfdd11e1d298d 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -534,16 +534,6 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
Triple.isAMDGPU() ? CmdArgs.push_back(Args.MakeArgString("-mcpu=" + Arch))
: CmdArgs.push_back(Args.MakeArgString("-march=" + Arch));
- // AMDGPU defaults to the LTO pipeline. Non-RDC HIP uses the conventional
- // non-LTO pipeline so device codegen still runs here, in parallel, instead
- // of being deferred to the LTO link.
- // FIXME: This is a stop-gap for non-RDC. Longer term, RDC and non-RDC should
- // share a unified interface so runtime libraries can be provided to non-RDC
- // compilations without relying on -mlink-builtin-bitcode.
- bool NonLTOAMDGPU = Triple.isAMDGPU() && Args.hasArg(OPT_no_lto);
- if (Triple.isAMDGPU() && !NonLTOAMDGPU)
- CmdArgs.push_back("-flto");
-
// Forward all of the `--offload-opt` and `-mllvm` options to the device.
for (auto &Arg : Args.filtered(OPT_offload_opt_eq_minus, OPT_mllvm))
CmdArgs.append(
@@ -557,7 +547,9 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
// Force the IR input language so Clang runs the compile and backend phases
// instead of treating them as linker inputs, which would defer codegen to
// the LTO link and defeat the non-LTO pipeline.
- if (NonLTOAMDGPU)
+ // FIXME: This is a stop-gap for non-RDC. Longer term, RDC and non-RDC should
+ // share a unified interface.
+ if (Args.hasArg(OPT_no_lto))
CmdArgs.append({"-x", "ir"});
for (StringRef InputFile : InputFiles)
CmdArgs.push_back(InputFile);
@@ -621,6 +613,9 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
for (StringRef Arg : Args.getAllArgValues(OPT_compiler_arg_EQ))
CmdArgs.push_back(Args.MakeArgString(Arg));
+ if (Args.hasArg(OPT_no_lto))
+ CmdArgs.append({"-flto=none", "-Wno-unused-command-line-argument"});
+
if (Error Err = executeCommands(*ClangPath, CmdArgs))
return std::move(Err);
More information about the cfe-commits
mailing list