================
@@ -914,15 +933,81 @@ bundleOmpAcc(ArrayRef<OffloadingImage> Images) {
 
 Expected<SmallVector<std::unique_ptr<MemoryBuffer>>>
 bundleSYCL(ArrayRef<OffloadingImage> Images) {
+  // clang-sycl-linker packs its outputs into one offload binary, which is
+  // passed to the offload wrapper as is.
   SmallVector<std::unique_ptr<MemoryBuffer>> Buffers;
+  if (Images.size() <= 1) {
+    for (const OffloadingImage &Image : Images)
+      Buffers.emplace_back(MemoryBuffer::getMemBufferCopy(
+          Image.Image->getBuffer(), Image.Image->getBufferIdentifier()));
+    return std::move(Buffers);
+  }
+
+  // Images for different IGCA targets or with different "code" are linked
+  // separately, but the SYCL runtime registers one offload binary per wrapper,
+  // so merge their device images into one.
+  SmallVector<std::unique_ptr<OffloadBinary>> Binaries;
+  SmallVector<OffloadingImage> Merged;
   for (const OffloadingImage &Image : Images) {
-    // clang-sycl-linker packs outputs into one binary blob. Therefore, it is
-    // passed to Offload Wrapper as is.
-    StringRef S(Image.Image->getBufferStart(), Image.Image->getBufferSize());
-    Buffers.emplace_back(
-        MemoryBuffer::getMemBufferCopy(S, Image.Image->getBufferIdentifier()));
+    // A dry run has no linked output to read.
+    if (Image.Image->getBufferSize() == 0)
+      continue;
+
+    // With --embed-bitcode, the image is the linked bitcode itself rather than
+    // an offload binary, so it is one device image.
+    if (identify_magic(Image.Image->getBuffer()) !=
+        file_magic::offload_binary) {
+      OffloadingImage Copy;
+      Copy.TheImageKind = Image.TheImageKind;
+      Copy.TheOffloadKind = Image.TheOffloadKind;
+      Copy.Flags = Image.Flags;
+      Copy.StringData = Image.StringData;
+      Copy.Image = MemoryBuffer::getMemBuffer(Image.Image->getMemBufferRef(),
+                                              
/*RequiresNullTerminator=*/false);
+      Merged.push_back(std::move(Copy));
+      continue;
+    }
----------------
YuriPlyakhin wrote:

As far as I can see, `--embed-bitcode` exists for `-fopenmp-target-jit`, the 
only case where the driver passes it and CUDA and HIP do not support it. 
libsycl can't run bitcode images.

Could we drop this branch and SYCL-MERGED-BC test?

An unsupported `--embed-bitcode` with several link groups would then fail when 
parsing the bitcode as an offload binary, which seems acceptable for a 
combination not produced/used by anyone.

If there is a SYCL use case for `--embed-bitcode`, could you please describe it?

https://github.com/llvm/llvm-project/pull/239010
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to