https://github.com/KseniyaTikhomirova created https://github.com/llvm/llvm-project/pull/231446
The libsycl only needs to know which binary format the image holds, and the architecture is the single canonical spelling of it: inputs may spell the same target as 'spirv64' or 'spirv64-unknown-unknown'. To avoid any runtime string copies or string manipulations, shorten the packed form to carry only necessary data. Assisted-by: Claude Code. >From 78c74be3632f7a17e452d90a387eb6ff6f78ef84 Mon Sep 17 00:00:00 2001 From: "Tikhomirova, Kseniya" <[email protected]> Date: Tue, 13 Oct 2026 03:14:00 -0700 Subject: [PATCH] [SYCL] Shorten triple form in device binary Signed-off-by: Tikhomirova, Kseniya <[email protected]> --- .../OffloadTools/clang-sycl-linker/triple.ll | 18 ++++++++++++++++++ .../clang-sycl-linker/ClangSYCLLinker.cpp | 6 +++++- .../src/detail/device_binary_structures.hpp | 4 +++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/clang/test/OffloadTools/clang-sycl-linker/triple.ll b/clang/test/OffloadTools/clang-sycl-linker/triple.ll index 7f432296acb8c..683941bab0e7c 100644 --- a/clang/test/OffloadTools/clang-sycl-linker/triple.ll +++ b/clang/test/OffloadTools/clang-sycl-linker/triple.ll @@ -10,6 +10,15 @@ ; RUN: | FileCheck %s --check-prefix=NO-TRIPLE-INPUT ; NO-TRIPLE-INPUT: sycl-bundle: image kind: spv, triple: spirv64, arch: {{$}} ; +; Test that only the architecture is recorded in the offload image, both when +; the full triple comes from -triple= and when it is inferred from the input. +; RUN: clang-sycl-linker --dry-run -v -triple=spirv64-unknown-unknown %t/no-triple.bc -o %t/short-explicit.out 2>&1 \ +; RUN: | FileCheck %s --check-prefix=SHORT-TRIPLE +; RUN: llvm-as %t/full-triple.ll -o %t/full-triple.bc +; RUN: clang-sycl-linker --dry-run -v %t/full-triple.bc -o %t/short-inferred.out 2>&1 \ +; RUN: | FileCheck %s --check-prefix=SHORT-TRIPLE +; SHORT-TRIPLE: sycl-bundle: image kind: spv, triple: spirv64, arch: {{$}} +; ; Test that triple was inferred from inputs and recorded in the offload image. ; RUN: llvm-as %t/input1.ll -o %t/input1.bc ; RUN: llvm-as %t/input2.ll -o %t/input2.bc @@ -81,6 +90,15 @@ define spir_kernel void @kernel_d() #0 { attributes #0 = { "sycl-module-id"="TU4.cpp" } +;--- full-triple.ll +target triple = "spirv64-unknown-unknown" + +define spir_kernel void @kernel_e() #0 { + ret void +} + +attributes #0 = { "sycl-module-id"="TU5.cpp" } + ;--- archive-full-triple.ll target triple = "spirv64-unknown-unknown" diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp index 60ab7dc4e2a7d..e65ea5eb29b61 100644 --- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp +++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp @@ -1043,8 +1043,12 @@ static Error runSYCLLink(ArrayRef<std::unique_ptr<MemoryBuffer>> Inputs, OffloadingImage TheImage{}; TheImage.TheImageKind = IsAOTCompileNeeded ? IMG_Object : IMG_SPIRV; TheImage.TheOffloadKind = OFK_SYCL; + // Pack the short form of the triple. The runtime only needs to know which + // binary format the image holds, and the architecture is the single + // canonical spelling of it: inputs may spell the same target as 'spirv64' + // or 'spirv64-unknown-unknown'. TheImage.StringData["triple"] = - Args.MakeArgString(Result.TargetTriple.str()); + Args.MakeArgString(Result.TargetTriple.getArchName()); TheImage.StringData["arch"] = Args.MakeArgString(Args.getLastArgValue(OPT_arch_EQ)); TheImage.StringData["symbols"] = SI.Symbols; diff --git a/libsycl/src/detail/device_binary_structures.hpp b/libsycl/src/detail/device_binary_structures.hpp index 29e71b45b3354..93aaafa8565f1 100644 --- a/libsycl/src/detail/device_binary_structures.hpp +++ b/libsycl/src/detail/device_binary_structures.hpp @@ -26,9 +26,11 @@ namespace detail { /// A device type represented by a particular target /// triple requires specific binary images. We need /// to map the image type onto the device target triple. +/// clang-sycl-linker packs the short form of the triple, i.e. the +/// architecture only, so these strings carry no vendor/OS components. /// SPIR-V with 64-bit pointers. -static constexpr char DeviceBinaryTripleSPIRV64[] = "spirv64-unknown-unknown"; +static constexpr char DeviceBinaryTripleSPIRV64[] = "spirv64"; } // namespace detail _LIBSYCL_END_NAMESPACE_SYCL _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
