diff --git a/clang/test/Driver/clang-offload-deps.c b/clang/test/Driver/clang-offload-deps.c index 65bfd0b45f6be..39b73c6ef6dee 100644 --- a/clang/test/Driver/clang-offload-deps.c +++ b/clang/test/Driver/clang-offload-deps.c @@ -23,15 +23,28 @@ // Generate dependencies for targets and check contents of the output bitcode files. // // RUN: clang-offload-deps -targets=openmp-x86_64-pc-linux-gnu,sycl-spir64 -outputs=%t.deps.x86_64,%t.deps.spir64 %t.fat +// RUN: clang-offload-deps -targets=openmp-x86_64-pc-linux-gnu,sycl-spir64 -outputs=%t.deps.x86_64,%t.deps.spir64 %t.fat // RUN: llvm-dis -o - %t.deps.x86_64 | FileCheck %s --check-prefixes=CHECK-DEPS-X86_64 -// RUN: llvm-dis -o - %t.deps.spir64 | FileCheck %s --check-prefixes=CHECK-DEPS-SPIR64 +// RUN: llvm-dis -o - %t.deps.spir64 | FileCheck %s --check-prefixes=CHECK-DEPS-SPIR64 -DSPIRTriple=spir64 +// +// Check that the legacy 'sycldevice' symbols are still identified correctly +// when 'unknown' environment has been specified/implied for SYCL via +// clang-offload-bundler's -targets +// +// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu,sycl-spir64-unknown-unknown-sycldevice -inputs=%t.host,%t.x86_64,%t.spir64 -outputs=%t.legacy-sycldevice.fat +// Check correct behavior for multiple targets +// RUN: clang-offload-deps -targets=openmp-x86_64-pc-linux-gnu,sycl-spir64-unknown-unknown -outputs=%t.deps.legacy.x86_64,%t.deps.legacy.spir64 %t.legacy-sycldevice.fat +// RUN: llvm-dis -o - %t.deps.legacy.spir64 | FileCheck %s --check-prefixes=CHECK-DEPS-SPIR64 -DSPIRTriple=spir64-unknown-unknown +// Check correct behavior for shortened triple +// RUN: clang-offload-deps -targets=sycl-spir64 -outputs=%t.deps.legacy.spir64-short %t.legacy-sycldevice.fat +// RUN: llvm-dis -o - %t.deps.legacy.spir64-short | FileCheck %s --check-prefixes=CHECK-DEPS-SPIR64 -DSPIRTriple=spir64 // CHECK-DEPS-X86_64: target triple = "x86_64-pc-linux-gnu" // CHECK-DEPS-X86_64: @bar = external global i8* // CHECK-DEPS-X86_64: @foo = external global i8* // CHECK-DEPS-X86_64: @offload.symbols = hidden local_unnamed_addr global [2 x i8*] [i8* bitcast (i8** @bar to i8*), i8* bitcast (i8** @foo to i8*)] -// CHECK-DEPS-SPIR64: target triple = "spir64" +// CHECK-DEPS-SPIR64: target triple = "[[SPIRTriple]]" // CHECK-DEPS-SPIR64: @bar = external global i8* // CHECK-DEPS-SPIR64: @foo = external global i8* // CHECK-DEPS-SPIR64: @llvm.used = appending global [2 x i8*] [i8* bitcast (i8** @bar to i8*), i8* bitcast (i8** @foo to i8*)], section "llvm.metadata" diff --git a/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp b/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp index a2c9711c1719b..1850aa75e1824 100644 --- a/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp +++ b/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp @@ -167,11 +167,33 @@ int main(int argc, const char **argv) { for (StringRef Symbol = DataOrErr.get(); !Symbol.empty();) { unsigned Len = strlen(Symbol.data()); + // TODO: Consider storing Targets and Kinds in a single map-like struct, + // possibly reusing ClangOffloadBundler's 'OffloadTargetInfo'. + auto KindsIter = Kinds.begin(); for (const std::string &Target : Targets) { std::string Prefix = Target + "."; if (Symbol.startswith(Prefix)) Target2Symbols[Target].insert( Symbol.substr(Prefix.size(), Len - Prefix.size())); + else if (KindsIter->equals("sycl")) { + // FIXME: Temporary solution for supporting libraries produced by old + // versions of SYCL toolchain. Old versions used triples with + // 'sycldevice' environment component of the triple, whereas new + // toolchain use 'unknown' value for that triple component. + // We check for the legacy 'sycldevice' variant upon the negative + // check for a SYCL triple with 'unknown' environment. + std::string LegacyPrefix(Target); + // In case vendor and OS are not set for this target, fill these with + // 'unknown' so that our target has the "canonical" form of: + // ---- + while (StringRef(LegacyPrefix).count("-") < 3) + LegacyPrefix += "-unknown"; + LegacyPrefix += "-sycldevice."; + if (Symbol.startswith(LegacyPrefix)) + Target2Symbols[Target].insert( + Symbol.substr(LegacyPrefix.size(), Len - LegacyPrefix.size())); + } + ++KindsIter; } Symbol = Symbol.drop_front(Len + 1u);