From 14a32a5629e732d28b1dcb8527f8c44e4f2fcbe0 Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Wed, 29 Nov 2023 09:31:35 -0800 Subject: [PATCH] [Driver][SYCL] Do not emit target not found in binary warning for early images For any objects/libraries created with -fno-sycl-rdc -c, we should not emit the 'linked binaries do not contain expected target' warning diagnostic. Expected use model is to not provide any specific targets to allow consuming of these objects/libraries. --- clang/lib/Driver/Driver.cpp | 21 ++++++++++++++++++++ clang/test/Driver/sycl-early-device-link.cpp | 2 ++ 2 files changed, 23 insertions(+) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index fae065f552d74..2a58823468a64 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -6145,6 +6145,27 @@ class OffloadingActionBuilder final { if (std::find(UniqueSections.begin(), UniqueSections.end(), SectionTriple) != UniqueSections.end()) continue; + // If any section found is an 'image' based object that was created + // with the intention of not requiring the matching SYCL target, do + // not emit the diagnostic. + if (SyclTarget.TC->getTriple().isSPIR()) { + bool SectionFound = false; + for (auto Section : UniqueSections) { + if (SectionFound) + break; + SmallVector ArchList = {"spir64_gen", "spir64_fpga", + "spir64_x86_64"}; + for (auto ArchStr : ArchList) { + std::string Arch(ArchStr + "_image"); + if (Section.find(Arch) != std::string::npos) { + SectionFound = true; + break; + } + } + } + if (SectionFound) + continue; + } // Didn't find any matches, return the full list for the diagnostic. SmallString<128> ArchListStr; int Cnt = 0; diff --git a/clang/test/Driver/sycl-early-device-link.cpp b/clang/test/Driver/sycl-early-device-link.cpp index b7ef7b0234235..f3ab4c8f016f0 100644 --- a/clang/test/Driver/sycl-early-device-link.cpp +++ b/clang/test/Driver/sycl-early-device-link.cpp @@ -121,11 +121,13 @@ // RUN: %clangxx -fsycl --target=x86_64-unknown-linux-gnu -### \ // RUN: %S/Inputs/SYCL/objgenimage.o %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=CONSUME_OBJ +// CONSUME_OBJ-NOT: linked binaries do not contain expected // CONSUME_OBJ: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_gen_image-unknown-unknown" "-input={{.*}}objgenimage.o" "-output=[[DEVICE_IMAGE_OBJ:.+\.o]] // CONSUME_OBJ: ld{{.*}} "[[DEVICE_IMAGE_OBJ]]" // RUN: %clangxx -fsycl --target=x86_64-unknown-linux-gnu -### \ // RUN: %S/Inputs/SYCL/libgenimage.a %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=CONSUME_LIB +// CONSUME_LIB-NOT: linked binaries do not contain expected // CONSUME_LIB: clang-offload-bundler{{.*}} "-type=aoo" "-targets=sycl-spir64_gen_image-unknown-unknown" "-input={{.*}}libgenimage.a" "-output=[[DEVICE_IMAGE_LIB:.+\.txt]] // CONSUME_LIB: ld{{.*}} "@[[DEVICE_IMAGE_LIB]]"