diff --git a/clang/docs/ClangOffloadBundler.rst b/clang/docs/ClangOffloadBundler.rst index 997948a8217e5..ebbd502865dab 100644 --- a/clang/docs/ClangOffloadBundler.rst +++ b/clang/docs/ClangOffloadBundler.rst @@ -174,7 +174,20 @@ Where: ============= ============================================================== **target-triple** - The target triple of the code object. + The target triple of the code object. See `Target Triple + `. + + The bundler accepts target triples with or without the optional environment + field: + + ``--``, or + ``---`` + + However, in order to standardize outputs for tools that consume bitcode + bundles, bundles written by the bundler internally use only the 4-field + target triple: + + ``---`` **target-id** The canonical target ID of the code object. Present only if the target diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index e313efb68b0df..d97b3082a0bb3 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -115,6 +115,21 @@ using namespace clang::driver; using namespace clang; using namespace llvm::opt; +// clang-offload-bundler is currently generating a 'standardized' target triple. +// Triple's format - Architecture-Vendor-OS-Environment. +// Bundle sections created by clang-offload-bundler contain the 'standardized' +// triple. This routine transforms the triple specified by user as input to this +// 'standardized' format to facilitate checks. +static std::string standardizedTriple(std::string OrigTriple) { + if (OrigTriple.back() == '-') // Already standardized + return OrigTriple; + llvm::Triple t = llvm::Triple(OrigTriple); + return llvm::Triple(t.getArchName(), t.getVendorName(), t.getOSName(), + t.getEnvironmentName()) + .str() + + "-"; +} + static std::optional getOffloadTargetTriple(const Driver &D, const ArgList &Args) { auto OffloadTargets = Args.getAllArgValues(options::OPT_offload_EQ); @@ -5975,7 +5990,7 @@ class OffloadingActionBuilder final { Arch = C.getDriver().MakeSYCLDeviceTriple("spir64_fpga").str(); if (std::find(UniqueSections.begin(), UniqueSections.end(), Arch) == UniqueSections.end()) - UniqueSections.push_back(Arch); + UniqueSections.push_back(standardizedTriple(Arch)); } } @@ -5988,7 +6003,7 @@ class OffloadingActionBuilder final { SectionTriple += "-"; SectionTriple += SyclTarget.BoundArch; } - + SectionTriple = standardizedTriple(SectionTriple); // If any matching section is found, we are good. if (std::find(UniqueSections.begin(), UniqueSections.end(), SectionTriple) != UniqueSections.end()) diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp index b3b8a65bed2fd..8c47f86223805 100644 --- a/clang/lib/Driver/OffloadBundler.cpp +++ b/clang/lib/Driver/OffloadBundler.cpp @@ -85,12 +85,25 @@ OffloadTargetInfo::OffloadTargetInfo(const StringRef Target, if (clang::StringToCudaArch(TripleOrGPU.second) != clang::CudaArch::UNKNOWN) { auto KindTriple = TripleOrGPU.first.split('-'); this->OffloadKind = KindTriple.first; - this->Triple = llvm::Triple(KindTriple.second); - this->TargetID = Target.substr(Target.find(TripleOrGPU.second)); + + // Enforce optional env field to standardize bundles + llvm::Triple t = llvm::Triple(KindTriple.second); + this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(), + t.getOSName(), t.getEnvironmentName()); + + if (TripleOrGPU.second.empty()) + this->TargetID = ""; + else + this->TargetID = Target.substr(Target.find(TripleOrGPU.second)); } else { auto KindTriple = TargetFeatures.first.split('-'); this->OffloadKind = KindTriple.first; - this->Triple = llvm::Triple(KindTriple.second); + + // Enforce optional env field to standardize bundles + llvm::Triple t = llvm::Triple(KindTriple.second); + this->Triple = llvm::Triple(t.getArchName(), t.getVendorName(), + t.getOSName(), t.getEnvironmentName()); + this->TargetID = ""; } } @@ -1577,34 +1590,34 @@ Error OffloadBundler::UnbundleFiles() { return Error::success(); } -// Unbundle the files. Return true if an error was found. +// Unbundle the files. Return false if an error was found. Expected clang::CheckBundledSection(const OffloadBundlerConfig &BundlerConfig) { // Open Input file. ErrorOr> CodeOrErr = MemoryBuffer::getFileOrSTDIN(BundlerConfig.InputFileNames.front()); if (std::error_code EC = CodeOrErr.getError()) - return createFileError(BundlerConfig.InputFileNames.front(), EC); + return false; MemoryBuffer &Input = *CodeOrErr.get(); // Select the right files handler. Expected> FileHandlerOrErr = CreateFileHandler(Input, BundlerConfig); if (!FileHandlerOrErr) - return FileHandlerOrErr.takeError(); + return false; std::unique_ptr &FH = *FileHandlerOrErr; // Quit if we don't have a handler. if (!FH) - return true; + return false; // Seed temporary filename generation with the stem of the input file. FH->SetTempFileNameBase(llvm::sys::path::stem(BundlerConfig.InputFileNames.front())); // Read the header of the bundled file. if (Error Err = FH->ReadHeader(Input)) - return std::move(Err); + return false; StringRef triple = BundlerConfig.TargetNames.front(); @@ -1615,13 +1628,15 @@ clang::CheckBundledSection(const OffloadBundlerConfig &BundlerConfig) { Expected> CurTripleOrErr = FH->ReadBundleStart(Input); if (!CurTripleOrErr) - return CurTripleOrErr.takeError(); + return false; // We don't have more bundles. if (!*CurTripleOrErr) break; - if (*CurTripleOrErr == triple) { + StringRef CurTriple = **CurTripleOrErr; + if (OffloadTargetInfo(CurTriple, BundlerConfig).Triple.str() == + OffloadTargetInfo(triple, BundlerConfig).Triple.str()) { found = true; break; } diff --git a/clang/test/Driver/Inputs/bundles/bundle_aft_standardization_of_target_triple.o b/clang/test/Driver/Inputs/bundles/bundle_aft_standardization_of_target_triple.o new file mode 100644 index 0000000000000..f63d320cfb078 Binary files /dev/null and b/clang/test/Driver/Inputs/bundles/bundle_aft_standardization_of_target_triple.o differ diff --git a/clang/test/Driver/Inputs/bundles/bundle_bef_standardization_of_target_triple.o b/clang/test/Driver/Inputs/bundles/bundle_bef_standardization_of_target_triple.o new file mode 100644 index 0000000000000..d5e4f422f930d Binary files /dev/null and b/clang/test/Driver/Inputs/bundles/bundle_bef_standardization_of_target_triple.o differ diff --git a/clang/test/Driver/clang-offload-bundler-asserts-on.c b/clang/test/Driver/clang-offload-bundler-asserts-on.c index aceda09f7bfa1..db99e31d568b9 100644 --- a/clang/test/Driver/clang-offload-bundler-asserts-on.c +++ b/clang/test/Driver/clang-offload-bundler-asserts-on.c @@ -21,12 +21,12 @@ // Tests to check compatibility between Bundle Entry ID formats i.e. between presence/absence of extra hyphen in case of missing environment field // RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-archive-gfx906-simple.a -output=%t-archive-gfx908-simple.a -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLECOMPATIBILITY -// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa-gfx906] : [Target: openmp-amdgcn-amd-amdhsa--gfx906] -// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: openmp-amdgcn-amd-amdhsa-gfx908] +// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa--gfx906] : [Target: openmp-amdgcn-amd-amdhsa--gfx906] +// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: openmp-amdgcn-amd-amdhsa--gfx908] // RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx906,hipv4-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-hip-archive-gfx906-simple.a -output=%t-hipv4-archive-gfx908-simple.a -hip-openmp-compatible -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=HIPOpenMPCOMPATIBILITY -// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa-gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906] -// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: hipv4-amdgcn-amd-amdhsa-gfx908] +// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa--gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906] +// HIPOpenMPCOMPATIBILITY: Compatible: Code Objects are compatible [CodeObject: openmp-amdgcn-amd-amdhsa--gfx908] : [Target: hipv4-amdgcn-amd-amdhsa--gfx908] // Some code so that we can create a binary out of this file. int A = 0; diff --git a/clang/test/Driver/clang-offload-bundler-old-bundle-with-new-bundler.c b/clang/test/Driver/clang-offload-bundler-old-bundle-with-new-bundler.c new file mode 100644 index 0000000000000..69ad5cc5c8b5e --- /dev/null +++ b/clang/test/Driver/clang-offload-bundler-old-bundle-with-new-bundler.c @@ -0,0 +1,10 @@ +// REQUIRES: x86-registered-target +// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}, system-windows + +// Check working of bundler before and after standardization +// RUN: clang-offload-bundler -type=o -targets=host-x86_64-unknown-linux-gnu,sycl-spir64-unknown-unknown -input=%S/Inputs/bundles/bundle_bef_standardization_of_target_triple.o -output=test-host-x86_64-unknown-linux-gnu.o -output=test-sycl-spir64-unknown-unknown.o -unbundle 2>&1 | FileCheck %s -check-prefix=CHECK-STD-OLD --allow-empty +// CHECK-STD-OLD-NOT: error: Can't find bundles for +// RUN: clang-offload-bundler -type=o -targets=host-x86_64-unknown-linux-gnu,sycl-spir64-unknown-unknown -input=%S/Inputs/bundles/bundle_aft_standardization_of_target_triple.o -output=test-host-x86_64-unknown-linux-gnu.o -output=test-sycl-spir64-unknown-unknown.o -unbundle 2>&1 | FileCheck %s -check-prefix=CHECK-STD-NEW --allow-empty +// CHECK-STD-NEW-NOT: error: Can't find bundles for + + diff --git a/clang/test/Driver/clang-offload-bundler-standardize.c b/clang/test/Driver/clang-offload-bundler-standardize.c new file mode 100644 index 0000000000000..397164464560f --- /dev/null +++ b/clang/test/Driver/clang-offload-bundler-standardize.c @@ -0,0 +1,35 @@ +// REQUIRES: x86-registered-target +// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}} + +// Generate the file we can bundle. +// RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.o + +// +// Generate a couple of files to bundle with. +// +// RUN: echo 'Content of device file 1' > %t.tgt1 +// RUN: echo 'Content of device file 2' > %t.tgt2 + +// +// Check code object compatibility for archive unbundling +// +// Create an object bundle with and without env fields +// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,hip-amdgcn-amd-amdhsa-gfx906,hip-amdgcn-amd-amdhsa-gfx908 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.no.env +// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple-,hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle.env + + +// Unbundle bundle.no.env while providing targets with env +// RUN: clang-offload-bundler -unbundle -type=o -targets=hip-amdgcn-amd-amdhsa--gfx906,hip-amdgcn-amd-amdhsa--gfx908 -input=%t.bundle.no.env -output=%t-hip-amdgcn-amd-amdhsa--gfx906.bc -output=%t-hip-amdgcn-amd-amdhsa--gfx908.bc -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLE-NO-ENV +// BUNDLE-NO-ENV: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906] +// BUNDLE-NO-ENV: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx908] : [Target: hip-amdgcn-amd-amdhsa--gfx908] + +// Unbundle bundle.env while providing targets with no env +// RUN: clang-offload-bundler -unbundle -type=o -targets=hip-amdgcn-amd-amdhsa-gfx906,hip-amdgcn-amd-amdhsa-gfx908 -input=%t.bundle.env -output=%t-hip-amdgcn-amd-amdhsa-gfx906.bc -output=%t-hip-amdgcn-amd-amdhsa-gfx908.bc -debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s -check-prefix=BUNDLE-ENV +// BUNDLE-ENV: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx906] : [Target: hip-amdgcn-amd-amdhsa--gfx906] +// BUNDLE-ENV: Compatible: Exact match: [CodeObject: hip-amdgcn-amd-amdhsa--gfx908] : [Target: hip-amdgcn-amd-amdhsa--gfx908] + +// Some code so that we can create a binary out of this file. +int A = 0; +void test_func(void) { + ++A; +} diff --git a/clang/test/Driver/clang-offload-bundler-tgtsym-asm.c b/clang/test/Driver/clang-offload-bundler-tgtsym-asm.c index cb9848b8df00e..c55cd6fd26232 100644 --- a/clang/test/Driver/clang-offload-bundler-tgtsym-asm.c +++ b/clang/test/Driver/clang-offload-bundler-tgtsym-asm.c @@ -13,8 +13,8 @@ // RUN: llvm-readobj --string-dump=.tgtsym %t.fat.o | FileCheck %s // CHECK: String dump of section '.tgtsym': -// CHECK-DAG: openmp-x86_64-pc-linux-gnu.foo -// CHECK-DAG: sycl-spir64.foo +// CHECK-DAG: openmp-x86_64-pc-linux-gnu-.foo +// CHECK-DAG: sycl-spir64----.foo __asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); void foo(void) {} diff --git a/clang/test/Driver/clang-offload-bundler-tgtsym.c b/clang/test/Driver/clang-offload-bundler-tgtsym.c index 04a65eb0be553..eac13b07d2c41 100644 --- a/clang/test/Driver/clang-offload-bundler-tgtsym.c +++ b/clang/test/Driver/clang-offload-bundler-tgtsym.c @@ -12,16 +12,16 @@ // RUN: llvm-readobj --string-dump=.tgtsym %t.fat.o | FileCheck %s // CHECK: String dump of section '.tgtsym': -// CHECK-DAG: openmp-x86_64-pc-linux-gnu.foo -// CHECK-DAG: openmp-x86_64-pc-linux-gnu.bar -// CHECK-DAG: sycl-spir64.foo -// CHECK-DAG: sycl-spir64.bar +// CHECK-DAG: openmp-x86_64-pc-linux-gnu-.foo +// CHECK-DAG: openmp-x86_64-pc-linux-gnu-.bar +// CHECK-DAG: sycl-spir64----.foo +// CHECK-DAG: sycl-spir64----.bar // CHECK-NOT: undefined_func // CHECK-NOT: static_func // CHECK-NOT: static_used -// CHECK-NOT: sycl-spir64.llvm.used -// CHECK-NOT: sycl-spir64.llvm.compiler.used -// CHECK-NOT: sycl-spir64.const_as +// CHECK-NOT: sycl-spir64----.llvm.used +// CHECK-NOT: sycl-spir64----.llvm.compiler.used +// CHECK-NOT: sycl-spir64----.const_as // RUN: clang-offload-bundler --add-target-symbols-to-bundled-object=false -type=o -targets=host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu,sycl-spir64 -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.fat.no.tgtsym.o // RUN: llvm-readobj --string-dump=.tgtsym %t.fat.no.tgtsym.o | FileCheck %s --check-prefix CHECK-NO-TGTSYM diff --git a/clang/test/Driver/clang-offload-bundler.c b/clang/test/Driver/clang-offload-bundler.c index 3cd48cab0ab20..1d4f24db11b4b 100644 --- a/clang/test/Driver/clang-offload-bundler.c +++ b/clang/test/Driver/clang-offload-bundler.c @@ -1,6 +1,7 @@ // REQUIRES: x86-registered-target -// REQUIRES: powerpc-registered-target -// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}} + +// TODO: Windows-related issue with temporary file creation - Fix and enable +// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}, system-windows // // Generate all the types of files we can bundle. @@ -311,11 +312,11 @@ // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o -### 2>&1 \ // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD -// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "--" "[[INOBJ1]]" "[[OUTOBJ]]" +// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude" "--" "[[INOBJ1]]" "[[OUTOBJ]]" // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o -### 2>&1 \ // RUN: | FileCheck %s -DHOST=%itanium_abi_triple -DINOBJ1=%t.o -DINOBJ2=%t.tgt1 -DINOBJ3=%t.tgt2 -DOUTOBJ=%t.bundle3.o --check-prefix CK-OBJ-CMD-INPUTS -// CK-OBJ-CMD-INPUTS: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "--" "[[INOBJ1]]" "[[OUTOBJ]]" +// CK-OBJ-CMD-INPUTS: llvm-objcopy{{(.exe)?}}" "--add-section=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-={{.*}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]-=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=[[INOBJ2]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu-=readonly,exclude" "--add-section=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=[[INOBJ3]]" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu-=readonly,exclude" "--" "[[INOBJ1]]" "[[OUTOBJ]]" // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bundle3.o // RUN: clang-offload-bundler -type=o -input=%t.bundle3.o -list | FileCheck -check-prefix=CKLST %s @@ -392,15 +393,14 @@ // RUN: diff %t.tgt2 %t.res.tgt2 // Check archive mode. -// RUN: clang-offload-bundler -type=a -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.host.a -output=%t.tgt1.a -output=%t.tgt2.a -input=%t.a -unbundle -// RUN: cmp %t.host.a %t.a +// RUN: clang-offload-bundler -type=a -targets=openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -output=%t.tgt1.a -output=%t.tgt2.a -input=%t.a -unbundle // RUN: llvm-ar t %t.tgt1.a | FileCheck %s --check-prefix=CHECK-AR-TGT1-LIST // RUN: llvm-ar t %t.tgt2.a | FileCheck %s --check-prefix=CHECK-AR-TGT2-LIST -// CHECK-AR-TGT1-LIST: openmp-powerpc64le-ibm-linux-gnu.{{.+}}.bundle3.o -// CHECK-AR-TGT1-LIST: openmp-powerpc64le-ibm-linux-gnu.{{.+}}.bundle4.o -// CHECK-AR-TGT2-LIST: openmp-x86_64-pc-linux-gnu.{{.+}}.bundle3.o -// CHECK-AR-TGT2-LIST: openmp-x86_64-pc-linux-gnu.{{.+}}.bundle4.o +// CHECK-AR-TGT1-LIST: openmp-powerpc64le-ibm-linux-gnu-{{.+}}.bundle3.o +// CHECK-AR-TGT1-LIST: openmp-powerpc64le-ibm-linux-gnu-{{.+}}.bundle4.o +// CHECK-AR-TGT2-LIST: openmp-x86_64-pc-linux-gnu-{{.+}}.bundle3.o +// CHECK-AR-TGT2-LIST: openmp-x86_64-pc-linux-gnu-{{.+}}.bundle4.o // // Check error due to missing bundles @@ -547,15 +547,15 @@ // RUN: llvm-ar t %t-archive-gfx906-simple.a | FileCheck %s -check-prefix=GFX906 // RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx906:xnack+ -input=%t.input-archive.a -output=%t-archive-gfx906-simple.a // RUN: llvm-ar t %t-archive-gfx906-simple.a | FileCheck %s -check-prefix=GFX906 -// GFX906: simple-openmp-amdgcn-amd-amdhsa-gfx906 +// GFX906: simple-openmp-amdgcn-amd-amdhsa--gfx906 // RUN: llvm-ar t %t-archive-gfx908-simple.a | FileCheck %s -check-prefix=GFX908 // GFX908-NOT: {{gfx906}} // RUN: not clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-amdgcn-amd-amdhsa-gfx906,openmp-amdgcn-amd-amdhsa-gfx906:sramecc+ -input=%t.o -input=%t.tgt1 -input=%t.tgt2 -output=%t.bad.bundle 2>&1 | FileCheck %s -check-prefix=BADTARGETS -// BADTARGETS: error: Cannot bundle inputs with conflicting targets: 'openmp-amdgcn-amd-amdhsa-gfx906' and 'openmp-amdgcn-amd-amdhsa-gfx906:sramecc+' +// BADTARGETS: error: Cannot bundle inputs with conflicting targets: 'openmp-amdgcn-amd-amdhsa--gfx906' and 'openmp-amdgcn-amd-amdhsa--gfx906:sramecc+' // Check for error if no compatible code object is found in the heterogeneous archive library // RUN: not clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx803 -input=%t.input-archive.a -output=%t-archive-gfx803-incompatible.a 2>&1 | FileCheck %s -check-prefix=INCOMPATIBLEARCHIVE -// INCOMPATIBLEARCHIVE: error: no compatible code object found for the target 'openmp-amdgcn-amd-amdhsa-gfx803' in heterogeneous archive library +// INCOMPATIBLEARCHIVE: error: no compatible code object found for the target 'openmp-amdgcn-amd-amdhsa--gfx803' in heterogeneous archive library // Check creation of empty archive if allow-missing-bundles is present and no compatible code object is found in the heterogeneous archive library // RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-amdgcn-amd-amdhsa-gfx803 -input=%t.input-archive.a -output=%t-archive-gfx803-empty.a -allow-missing-bundles @@ -565,7 +565,7 @@ // Check compatibility of OpenMP code objects found in the heterogeneous archive library with HIP code objects of the target // RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa-gfx906,hipv4-amdgcn-amd-amdhsa-gfx908 -input=%t.input-archive.a -output=%t-hip-archive-gfx906-simple.a -output=%t-hipv4-archive-gfx908-simple.a -hip-openmp-compatible // RUN: llvm-ar t %t-hip-archive-gfx906-simple.a | FileCheck %s -check-prefix=HIPOPENMPCOMPAT -// HIPOPENMPCOMPAT: simple-openmp-amdgcn-amd-amdhsa-gfx906 +// HIPOPENMPCOMPAT: simple-openmp-amdgcn-amd-amdhsa--gfx906 // RUN: llvm-ar t %t-hipv4-archive-gfx908-simple.a | FileCheck %s -check-prefix=HIPv4OPENMPCOMPAT // HIPv4OPENMPCOMPAT: simple-openmp-amdgcn-amd-amdhsa--gfx908 diff --git a/clang/test/Driver/sycl-no-rdc-errors.cpp b/clang/test/Driver/sycl-no-rdc-errors.cpp index 3506333efcc9e..10bae53ace443 100644 --- a/clang/test/Driver/sycl-no-rdc-errors.cpp +++ b/clang/test/Driver/sycl-no-rdc-errors.cpp @@ -5,7 +5,7 @@ // RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,sycl-spir64_gen-unknown-unknown -input=%t -input=%t.o -output=%t.fat.o // RUN: not %clang -### -fsycl -fno-sycl-rdc %t.fat.o 2>&1 | FileCheck -check-prefix=CHECK-ARCH %s -// CHECK-ARCH: error: linked binaries do not contain expected 'spir64-unknown-unknown' target; found targets: 'spir64_gen-unknown-unknown', this is not supported with '-fno-sycl-rdc' +// CHECK-ARCH: error: linked binaries do not contain expected 'spir64-unknown-unknown--' target; found targets: 'spir64_gen-unknown-unknown--', this is not supported with '-fno-sycl-rdc' // Some code so that we can create a binary out of this file. void test_func(void) { diff --git a/clang/test/Driver/sycl-target-mismatch.cpp b/clang/test/Driver/sycl-target-mismatch.cpp index 8b22ee45e6a89..ce22e45a81ade 100644 --- a/clang/test/Driver/sycl-target-mismatch.cpp +++ b/clang/test/Driver/sycl-target-mismatch.cpp @@ -8,7 +8,7 @@ // RUN: %clangxx -fsycl -fsycl-targets=spir64_gen %S/Inputs/SYCL/objlin64.o \ // RUN: -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=SPIR64_GEN_DIAG -// SPIR64_GEN_DIAG: linked binaries do not contain expected 'spir64_gen-unknown-unknown' target; found targets: 'spir64-unknown-unknown{{.*}}, spir64-unknown-unknown{{.*}}' [-Wsycl-target] +// SPIR64_GEN_DIAG: linked binaries do not contain expected 'spir64_gen-unknown-unknown--' target; found targets: 'spir64-unknown-unknown{{.*}}, spir64-unknown-unknown{{.*}}' [-Wsycl-target] // RUN: %clangxx -fsycl -fsycl-targets=spir64 %S/Inputs/SYCL/liblin64.a \ // RUN: -### %s 2>&1 \ @@ -33,7 +33,7 @@ // RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_60 \ // RUN: %S/Inputs/SYCL/objnvptx64-sm_50.o -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=NVPTX64_DIAG -// NVPTX64_DIAG: linked binaries do not contain expected 'nvptx64-nvidia-cuda-sm_60' target; found targets: 'nvptx64-nvidia-cuda-sm_50' [-Wsycl-target] +// NVPTX64_DIAG: linked binaries do not contain expected 'nvptx64-nvidia-cuda-sm_60-' target; found targets: 'nvptx64-nvidia-cuda-sm_50-' [-Wsycl-target] // RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_50 \ // RUN: %S/Inputs/SYCL/libnvptx64-sm_50.a -### %s 2>&1 \ @@ -61,7 +61,7 @@ // RUN: %clangxx -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx906 \ // RUN: %S/Inputs/SYCL/objamdgcn-gfx908.o -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=AMDGCN_DIAG -// AMDGCN_DIAG: linked binaries do not contain expected 'amdgcn-amd-amdhsa-gfx906' target; found targets: 'amdgcn-amd-amdhsa-gfx908' [-Wsycl-target] +// AMDGCN_DIAG: linked binaries do not contain expected 'amdgcn-amd-amdhsa-gfx906-' target; found targets: 'amdgcn-amd-amdhsa-gfx908-' [-Wsycl-target] // RUN: %clangxx -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 \ // RUN: %S/Inputs/SYCL/libamdgcn-gfx908.a -### %s 2>&1 \ diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index 6920e1ce86e5a..c8400ae5cd2e2 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -390,6 +390,8 @@ int main(int argc, const char **argv) { llvm::DenseSet ParsedTargets; // Map {offload-kind}-{triple} to target IDs. std::map> TargetIDs; + // Standardize target names to include env field + std::vector StandardizedTargetNames; for (StringRef Target : TargetNames) { if (ParsedTargets.contains(Target)) { reportError(createStringError(errc::invalid_argument, @@ -401,6 +403,8 @@ int main(int argc, const char **argv) { bool KindIsValid = OffloadInfo.isOffloadKindValid(); bool TripleIsValid = OffloadInfo.isTripleValid(); + StandardizedTargetNames.push_back(OffloadInfo.str()); + if (!KindIsValid || !TripleIsValid) { SmallVector Buf; raw_svector_ostream Msg(Buf); @@ -425,6 +429,9 @@ int main(int argc, const char **argv) { ++Index; } + + BundlerConfig.TargetNames = StandardizedTargetNames; + for (const auto &TargetID : TargetIDs) { if (auto ConflictingTID = clang::getConflictTargetIDCombination(TargetID.second)) { diff --git a/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp b/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp index 835027f8db560..979462a91ecd5 100644 --- a/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp +++ b/clang/tools/clang-offload-deps/ClangOffloadDeps.cpp @@ -74,6 +74,24 @@ static void reportError(Error E) { logAllUnhandledErrors(std::move(E), WithColor::error(errs(), ToolPath)); } +// clang-offload-bundler is currently generating a 'standardized' target header. +// This is of the following form - Kind-Triple-TargetID where triple's format is +// Architecture-Vendor-OS-Environment +// This routine transforms the target header specified by user as input to +// clang-offload-deps to this 'standardized' format. +static std::string standardizedTarget(std::string OrigTarget) { + if (OrigTarget.back() == '-') // Already standardized + return OrigTarget; + StringRef Target(OrigTarget); + auto KindTriple = Target.split('-'); + llvm::Triple t = llvm::Triple(KindTriple.second); + return std::string(KindTriple.first) + "-" + + std::string(llvm::Triple(t.getArchName(), t.getVendorName(), + t.getOSName(), t.getEnvironmentName()) + .str()) + + "-"; +} + int main(int argc, const char **argv) { sys::PrintStackTraceOnErrorSignal(argv[0]); ToolPath = argv[0]; @@ -168,11 +186,10 @@ int main(int argc, const char **argv) { // offload targets and insert them into the map. 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'. for (const std::string &Target : Targets) { - std::string Prefix = Target + "."; + std::string Prefix = standardizedTarget(Target) + "."; if (Symbol.startswith(Prefix)) Target2Symbols[Target].insert( Symbol.substr(Prefix.size(), Len - Prefix.size()));