Skip to content

Commit 94f9d5d

Browse files
authored
[Offload] Treat an empty packager architecture as 'generic' (llvm#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.
1 parent 04589d1 commit 94f9d5d

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9163,7 +9163,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
91639163
SmallVector<std::string> Parts{
91649164
"file=" + File.str(),
91659165
"triple=" + TC->getTripleString(),
9166-
"arch=" + Arch.str(),
9166+
"arch=" + (Arch.empty() ? "generic" : Arch.str()),
91679167
"kind=" + Kind.str(),
91689168
};
91699169

clang/test/Driver/linker-wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ __attribute__((visibility("protected"), used)) int x;
5959
// RUN: --linker-path=/usr/bin/ld.lld --whole-archive %t.a --no-whole-archive \
6060
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
6161

62-
// 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
62+
// 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
6363

6464
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
6565
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -openmp-opt-disable \

clang/test/Driver/sycl-offload-jit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// CHK-DEVICE-TRIPLE-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
2828
// CHK-DEVICE-TRIPLE-SAME: "-fsycl-is-device"
2929
// CHK-DEVICE-TRIPLE-SAME: "-O2"
30-
// CHK-DEVICE-TRIPLE: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=,kind=sycl"
30+
// CHK-DEVICE-TRIPLE: clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=spirv64-unknown-unknown,arch=generic,kind=sycl"
3131

3232
/// Check -fsycl-is-device is passed when compiling for the device.
3333
/// Check -fsycl-is-host is passed when compiling for host.

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,6 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
474474

475475
const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ));
476476
StringRef Arch = Args.getLastArgValue(OPT_arch_EQ);
477-
if (Arch.empty())
478-
Arch = "native";
479477
// Create a new file to write the linked device image to. Assume that the
480478
// input filename already has the device and architecture.
481479
auto TempFileOrErr =
@@ -492,11 +490,14 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
492490
"-o",
493491
*TempFileOrErr,
494492
Args.MakeArgString("--target=" + Triple.getTriple()),
495-
Triple.isAMDGPU() ? Args.MakeArgString("-mcpu=" + Arch)
496-
: Args.MakeArgString("-march=" + Arch),
497-
Args.MakeArgString("-" + OptLevel),
498493
};
499494

495+
if (!Arch.empty())
496+
Triple.isAMDGPU() ? CmdArgs.push_back(Args.MakeArgString("-mcpu=" + Arch))
497+
: CmdArgs.push_back(Args.MakeArgString("-march=" + Arch));
498+
499+
CmdArgs.push_back(Args.MakeArgString("-" + OptLevel));
500+
500501
// Forward all of the `--offload-opt` and similar options to the device.
501502
CmdArgs.push_back("-flto");
502503
for (auto &Arg : Args.filtered(OPT_offload_opt_eq_minus, OPT_mllvm))
@@ -826,8 +827,9 @@ DerivedArgList getLinkerArgs(ArrayRef<OffloadFile> Input,
826827

827828
// Set the subarchitecture and target triple for this compilation.
828829
const OptTable &Tbl = getOptTable();
830+
StringRef Arch = Args.MakeArgString(Input.front().getBinary()->getArch());
829831
DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_arch_EQ),
830-
Args.MakeArgString(Input.front().getBinary()->getArch()));
832+
Arch == "generic" ? "" : Arch);
831833
DAL.AddJoinedArg(nullptr, Tbl.getOption(OPT_triple_EQ),
832834
Args.MakeArgString(Input.front().getBinary()->getTriple()));
833835

0 commit comments

Comments
 (0)