[llvm] [llvm-objdump] Add support for HIP offload bundles (PR #114834)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 20:06:21 PST 2025


================
@@ -64,6 +68,47 @@ void llvm::dumpOffloadBinary(const ObjectFile &O) {
   // Print out all the binaries that are contained in this buffer.
   for (uint64_t I = 0, E = Binaries.size(); I != E; ++I)
     printBinary(*Binaries[I].getBinary(), I);
+
+  dumpOffloadBundleFatBinary(O, ArchName);
+}
+
+// Given an Object file, collect all Bundles of FatBin Binaries
+// and dump them into Code Object files
+// if -arch=-name is specified, only dump the Entries that match the target arch
+void llvm::dumpOffloadBundleFatBinary(const ObjectFile &O, StringRef ArchName) {
+  assert((O.isELF() || O.isCOFF()) && "Invalid file type");
+  if (!O.isELF() && !O.isCOFF()) {
+    reportWarning(
+        "--offloading is currently only supported for COFF and ELF targets",
+        O.getFileName());
+    return;
+  }
+
+  SmallVector<llvm::object::OffloadBundleFatBin> FoundBundles;
+  SmallVector<llvm::object::OffloadBundleEntry> FoundEntries;
+
+  if (Error Err = llvm::object::extractOffloadBundleFatBinary(O, FoundBundles))
+    reportError(O.getFileName(), "while extracting offload FatBin bundles: " +
+                                     toString(std::move(Err)));
+
+  for (const auto &[bundle_num, Bundle] : llvm::enumerate(FoundBundles)) {
----------------
jhuber6 wrote:

```suggestion
  for (const auto &[BundleNum, Bundle] : llvm::enumerate(FoundBundles)) {
```

https://github.com/llvm/llvm-project/pull/114834


More information about the llvm-commits mailing list