Author: Yury Plyakhin Date: 2026-02-11T10:21:22-08:00 New Revision: 81f445b7df94de485240b21034682f22432729c4
URL: https://github.com/llvm/llvm-project/commit/81f445b7df94de485240b21034682f22432729c4 DIFF: https://github.com/llvm/llvm-project/commit/81f445b7df94de485240b21034682f22432729c4.diff LOG: [clang-sycl-linker][offload] Set TheImageKind based on IsAOTCompileNeeded flag (#180269) Previously, TheImageKind was set to IMG_None and relied on a runtime heuristic to determine the correct image type. This commit sets it explicitly to IMG_Object for AOT-compiled images and IMG_SPIRV for SPIR-V images based on the IsAOTCompileNeeded flag. Also it adds test for this change, which required minor changes in OffloadBinary and OffloadDump. Added: Modified: clang/test/Driver/clang-sycl-linker-test.cpp clang/test/lit.cfg.py clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp llvm/lib/Object/OffloadBinary.cpp llvm/tools/llvm-objdump/OffloadDump.cpp Removed: ################################################################################ diff --git a/clang/test/Driver/clang-sycl-linker-test.cpp b/clang/test/Driver/clang-sycl-linker-test.cpp index 55f56bd2958f7..74543885e32af 100644 --- a/clang/test/Driver/clang-sycl-linker-test.cpp +++ b/clang/test/Driver/clang-sycl-linker-test.cpp @@ -5,10 +5,14 @@ // Test the dry run of a simple case to link two input files. // RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_1.bc // RUN: %clangxx -emit-llvm -c -target spirv64 %s -o %t_2.bc -// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t_1.bc %t_2.bc -o a.spv 2>&1 \ +// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 %t_1.bc %t_2.bc -o %t-spirv.out 2>&1 \ // RUN: | FileCheck %s --check-prefix=SIMPLE-FO // SIMPLE-FO: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc libfiles: output: [[LLVMLINKOUT:.*]].bc -// SIMPLE-FO-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: a_0.spv +// SIMPLE-FO-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: {{.*}}_0.spv +// +// Test that IMG_SPIRV image kind is set for non-AOT compilation. +// RUN: llvm-objdump --offloading %t-spirv.out | FileCheck %s --check-prefix=IMAGE-KIND-SPIRV +// IMAGE-KIND-SPIRV: kind spir-v // // Test the dry run of a simple case with device library files specified. // RUN: mkdir -p %t.dir @@ -34,27 +38,34 @@ // DEVLIBSERR2: '{{.*}}lib3.bc' SYCL device library file is not found // // Test AOT compilation for an Intel GPU. -// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 -arch=bmg_g21 %t_1.bc %t_2.bc -o a.out 2>&1 \ +// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 -arch=bmg_g21 %t_1.bc %t_2.bc -o %t-aot-gpu.out 2>&1 \ // RUN: --ocloc-options="-a -b" \ // RUN: | FileCheck %s --check-prefix=AOT-INTEL-GPU // AOT-INTEL-GPU: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc libfiles: output: [[LLVMLINKOUT:.*]].bc // AOT-INTEL-GPU-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: [[SPIRVTRANSLATIONOUT:.*]]_0.spv -// AOT-INTEL-GPU-NEXT: "{{.*}}ocloc{{.*}}" {{.*}}-device bmg_g21 -a -b {{.*}}-output a_0.out -file [[SPIRVTRANSLATIONOUT]]_0.spv +// AOT-INTEL-GPU-NEXT: "{{.*}}ocloc{{.*}}" {{.*}}-device bmg_g21 -a -b {{.*}}-output [[SPIRVTRANSLATIONOUT]]_0.out -file [[SPIRVTRANSLATIONOUT]]_0.spv +// +// Test that IMG_Object image kind is set for AOT compilation (Intel GPU). +// RUN: llvm-objdump --offloading %t-aot-gpu.out | FileCheck %s --check-prefix=IMAGE-KIND-OBJECT +// IMAGE-KIND-OBJECT: kind elf // // Test AOT compilation for an Intel CPU. -// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 -arch=graniterapids %t_1.bc %t_2.bc -o a.out 2>&1 \ +// RUN: clang-sycl-linker --dry-run -v -triple=spirv64 -arch=graniterapids %t_1.bc %t_2.bc -o %t-aot-cpu.out 2>&1 \ // RUN: --opencl-aot-options="-a -b" \ // RUN: | FileCheck %s --check-prefix=AOT-INTEL-CPU // AOT-INTEL-CPU: sycl-device-link: inputs: {{.*}}.bc, {{.*}}.bc libfiles: output: [[LLVMLINKOUT:.*]].bc // AOT-INTEL-CPU-NEXT: LLVM backend: input: [[LLVMLINKOUT]].bc, output: [[SPIRVTRANSLATIONOUT:.*]]_0.spv -// AOT-INTEL-CPU-NEXT: "{{.*}}opencl-aot{{.*}}" {{.*}}--device=cpu -a -b {{.*}}-o a_0.out [[SPIRVTRANSLATIONOUT]]_0.spv +// AOT-INTEL-CPU-NEXT: "{{.*}}opencl-aot{{.*}}" {{.*}}--device=cpu -a -b {{.*}}-o [[SPIRVTRANSLATIONOUT]]_0.out [[SPIRVTRANSLATIONOUT]]_0.spv +// +// Test that IMG_Object image kind is set for AOT compilation (Intel CPU). +// RUN: llvm-objdump --offloading %t-aot-cpu.out | FileCheck %s --check-prefix=IMAGE-KIND-OBJECT // // Check that the output file must be specified. -// RUN: not clang-sycl-linker --dry-run %t_1.bc %t_2.bc 2>& 1 \ +// RUN: not clang-sycl-linker --dry-run %t_1.bc %t_2.bc 2>&1 \ // RUN: | FileCheck %s --check-prefix=NOOUTPUT // NOOUTPUT: Output file must be specified // -// Check that the target triple must be. -// RUN: not clang-sycl-linker --dry-run %t_1.bc %t_2.bc -o a.out 2>& 1 \ +// Check that the target triple must be specified. +// RUN: not clang-sycl-linker --dry-run %t_1.bc %t_2.bc -o a.out 2>&1 \ // RUN: | FileCheck %s --check-prefix=NOTARGET // NOTARGET: Target triple must be specified diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py index c5e03e8e88aad..6796c64fc4778 100644 --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -103,6 +103,7 @@ "clang- diff ", "clang-format", "clang-repl", + "llvm-objdump", "llvm-offload-binary", "clang-tblgen", "clang-scan-deps", diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp index 84e0a15d2c498..a62425069aa90 100644 --- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp +++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp @@ -545,13 +545,7 @@ Error runSYCLLink(ArrayRef<std::string> Files, const ArgList &Args) { return createFileError(File, EC); } OffloadingImage TheImage{}; - // TODO: TheImageKind should be - // `IsAOTCompileNeeded ? IMG_Object : IMG_SPIRV;` - // For that we need to update SYCL Runtime to align with the ImageKind enum. - // Temporarily it is initalized to IMG_None, because in that case, SYCL - // Runtime has a heuristic to understand what the Image Kind is, so at least - // it works. - TheImage.TheImageKind = IMG_None; + TheImage.TheImageKind = IsAOTCompileNeeded ? IMG_Object : IMG_SPIRV; TheImage.TheOffloadKind = OFK_SYCL; TheImage.StringData["triple"] = Args.MakeArgString(Args.getLastArgValue(OPT_triple_EQ)); diff --git a/llvm/lib/Object/OffloadBinary.cpp b/llvm/lib/Object/OffloadBinary.cpp index 79c1e42392920..f535f44773578 100644 --- a/llvm/lib/Object/OffloadBinary.cpp +++ b/llvm/lib/Object/OffloadBinary.cpp @@ -423,6 +423,7 @@ ImageKind object::getImageKind(StringRef Name) { .Case("cubin", IMG_Cubin) .Case("fatbin", IMG_Fatbinary) .Case("s", IMG_PTX) + .Case("spv", IMG_SPIRV) .Default(IMG_None); } @@ -438,6 +439,8 @@ StringRef object::getImageKindName(ImageKind Kind) { return "fatbin"; case IMG_PTX: return "s"; + case IMG_SPIRV: + return "spv"; default: return ""; } diff --git a/llvm/tools/llvm-objdump/OffloadDump.cpp b/llvm/tools/llvm-objdump/OffloadDump.cpp index a77537dd90eeb..cd2727069c2e9 100644 --- a/llvm/tools/llvm-objdump/OffloadDump.cpp +++ b/llvm/tools/llvm-objdump/OffloadDump.cpp @@ -36,6 +36,8 @@ static StringRef getImageName(const OffloadBinary &OB) { return "fatbinary"; case IMG_PTX: return "ptx"; + case IMG_SPIRV: + return "spir-v"; default: return "<none>"; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
