[clang] 94f9d5d - [Offload] Treat an empty packager architecture as 'generic' (#126655)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 11 07:13:40 PST 2025
Author: Joseph Huber
Date: 2025-02-11T09:13:35-06:00
New Revision: 94f9d5d1a8257710f0483ce025e19a6326ca6e4b
URL: https://github.com/llvm/llvm-project/commit/94f9d5d1a8257710f0483ce025e19a6326ca6e4b
DIFF: https://github.com/llvm/llvm-project/commit/94f9d5d1a8257710f0483ce025e19a6326ca6e4b.diff
LOG: [Offload] Treat an empty packager architecture as 'generic' (#126655)
Summary:
The `clang-offload-packager` records the architecture of the job.
Currently there are cases where this will be empty. SYCL, CPU, and when
the user manually overrides it to be empty. In these cases we should
alwas consider it 'generic'. Adding this string both makes it clear how
it behaves and triggers the special handling for this architecture,
allowing it to bind to different architectures.
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/linker-wrapper.c
clang/test/Driver/sycl-offload-jit.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index ea376ac00d910..5deafa2ad0f4a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9163,7 +9163,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
SmallVector<std::string> Parts{
"file=" + File.str(),
"triple=" + TC->getTripleString(),
- "arch=" + Arch.str(),
+ "arch=" + (Arch.empty() ? "generic" : Arch.str()),
"kind=" + Kind.str(),
};
diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c
index f416ee5f4463b..df0a1d1e9a84d 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -59,7 +59,7 @@ __attribute__((visibility("protected"), used)) int x;
// RUN: --linker-path=/usr/bin/ld.lld --whole-archive %t.a --no-whole-archive \
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
-// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -march=native -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
+// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -openmp-opt-disable \
diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp
index eb192e08a3bc0..e040f4ded18e9 100644
--- a/clang/test/Driver/sycl-offload-jit.cpp
+++ b/clang/test/Driver/sycl-offload-jit.cpp
@@ -27,7 +27,7 @@
// CHK-DEVICE-TRIPLE-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
// CHK-DEVICE-TRIPLE-SAME: "-fsycl-is-device"
// CHK-DEVICE-TRIPLE-SAME: "-O2"
-// CHK-DEVICE-TRIPLE: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=,kind=sycl"
+// CHK-DEVICE-TRIPLE: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl"
/// Check -fsycl-is-device is passed when compiling for the device.
/// Check -fsycl-is-host is passed when compiling for host.
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index b189cfee674dd..aa43b2f5f2a1b 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -474,8 +474,6 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
StringRef Arch = Args.getLastArgValue(OPT_arch_EQ);
- if (Arch.empty())
- Arch = "native";
// Create a new file to write the linked device image to. Assume that the
// input filename already has the device and architecture.
auto TempFileOrErr =
@@ -492,11 +490,14 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
"-o",
*TempFileOrErr,
Args.MakeArgString("--target=" + Triple.getTriple()),
- Triple.isAMDGPU() ? Args.MakeArgString("-mcpu=" + Arch)
- : Args.MakeArgString("-march=" + Arch),
- Args.MakeArgString("-" + OptLevel),
};
+ if (!Arch.empty())
+ Triple.isAMDGPU() ? CmdArgs.push_back(Args.MakeArgString("-mcpu=" + Arch))
+ : CmdArgs.push_back(Args.MakeArgString("-march=" + Arch));
+
+ CmdArgs.push_back(Args.MakeArgString("-" + OptLevel));
+
// Forward all of the `--offload-opt` and similar options to the device.
CmdArgs.push_back("-flto");
for (auto &Arg : Args.filtered(OPT_offload_opt_eq_minus, OPT_mllvm))
@@ -826,8 +827,9 @@ DerivedArgList getLinkerArgs(ArrayRef<OffloadFile> Input,
// Set the subarchitecture and target triple for this compilation.
const OptTable &Tbl = getOptTable();
+ StringRef Arch = Args.MakeArgString(Input.front().getBinary()->getArch());
DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_arch_EQ),
- Args.MakeArgString(Input.front().getBinary()->getArch()));
+ Arch == "generic" ? "" : Arch);
DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_triple_EQ),
Args.MakeArgString(Input.front().getBinary()->getTriple()));
More information about the cfe-commits
mailing list