[clang] [Offload] Treat an empty packager archicture as 'generic' (PR #126655)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 11 06:36:40 PST 2025
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/126655
>From 32907913dc72a0d314e9ea9a75f0d3191e7fcb7f Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 10 Feb 2025 20:30:41 -0600
Subject: [PATCH] [Offload] Treat an empty packager archicture as 'generic'
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.
---
clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
clang/test/Driver/linker-wrapper.c | 2 +-
clang/test/Driver/sycl-offload-jit.cpp | 2 +-
.../clang-linker-wrapper/ClangLinkerWrapper.cpp | 14 ++++++++------
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index ea376ac00d9108b..5deafa2ad0f4a68 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 f416ee5f4463bcc..df0a1d1e9a84de1 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 eb192e08a3bc0c5..e040f4ded18e92f 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 b189cfee674dd3e..aa43b2f5f2a1b32 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