https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/126655
>From 050abedb87283e8ee31a95366866fa5c22d1719e Mon Sep 17 00:00:00 2001 From: Joseph Huber <hube...@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/sycl-offload-jit.cpp | 2 +- .../clang-linker-wrapper/ClangLinkerWrapper.cpp | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index ea376ac00d9108..5deafa2ad0f4a6 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/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp index eb192e08a3bc0c..e040f4ded18e92 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 b189cfee674dd3..aa43b2f5f2a1b3 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())); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits