-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Offloading] Extend OffloadBinary format to support multiple metadata entries #169425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions cpp,c,h -- clang/test/Driver/linker-wrapper-image.c llvm/include/llvm/Object/OffloadBinary.h llvm/include/llvm/ObjectYAML/OffloadYAML.h llvm/lib/Frontend/Offloading/OffloadWrapper.cpp llvm/lib/Object/OffloadBinary.cpp llvm/lib/ObjectYAML/OffloadEmitter.cpp llvm/lib/ObjectYAML/OffloadYAML.cpp llvm/tools/llvm-objdump/OffloadDump.cpp llvm/tools/llvm-offload-binary/llvm-offload-binary.cpp llvm/tools/obj2yaml/offload2yaml.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h
index 84ebf51db..a63ea77d1 100644
--- a/llvm/include/llvm/Object/OffloadBinary.h
+++ b/llvm/include/llvm/Object/OffloadBinary.h
@@ -95,7 +95,8 @@ public:
};
using StringMap = MapVector<StringRef, StringRef>;
- using entry_iterator = SmallVector<std::pair<const Entry *, StringMap>, 1>::const_iterator;
+ using entry_iterator =
+ SmallVector<std::pair<const Entry *, StringMap>, 1>::const_iterator;
using entry_iterator_range = iterator_range<entry_iterator>;
using string_iterator = MapVector<StringRef, StringRef>::const_iterator;
using string_iterator_range = iterator_range<string_iterator>;
@@ -128,7 +129,9 @@ public:
return Entries[0].first->TheImageKind;
}
- OffloadKind getOffloadKind() const { return Entries[0].first->TheOffloadKind; }
+ OffloadKind getOffloadKind() const {
+ return Entries[0].first->TheOffloadKind;
+ }
uint32_t getVersion() const { return TheHeader->Version; }
uint32_t getFlags() const { return Entries[0].first->Flags; }
uint64_t getSize() const { return TheHeader->Size; }
@@ -137,7 +140,8 @@ public:
StringRef getTriple() const { return getString("triple"); }
StringRef getArch() const { return getString("arch"); }
StringRef getImage() const {
- return StringRef(&Buffer[Entries[0].first->ImageOffset], Entries[0].first->ImageSize);
+ return StringRef(&Buffer[Entries[0].first->ImageOffset],
+ Entries[0].first->ImageSize);
}
// Iterator access to all entries in the binary
@@ -156,7 +160,9 @@ public:
// Iterator over all the key and value pairs in the binary.
string_iterator_range strings() const { return Entries[0].second; }
- StringRef getString(StringRef Key) const { return Entries[0].second.lookup(Key); }
+ StringRef getString(StringRef Key) const {
+ return Entries[0].second.lookup(Key);
+ }
static bool classof(const Binary *V) { return V->isOffloadFile(); }
@@ -172,8 +178,8 @@ private:
StringMap Strings;
for (uint64_t SI = 0, SE = TheEntry->NumStrings; SI != SE; ++SI) {
StringRef Key = &Buffer[StringMapBegin[SI].KeyOffset];
- StringRef Value = StringRef(
- &Buffer[StringMapBegin[SI].ValueOffset], StringMapBegin[SI].ValueSize);
+ StringRef Value = StringRef(&Buffer[StringMapBegin[SI].ValueOffset],
+ StringMapBegin[SI].ValueSize);
Strings.insert({Key, Value});
}
Entries.push_back(std::make_pair(TheEntry, std::move(Strings)));
|
🐧 Linux x64 Test Results
All tests passed but another part of the build failed. Click on a failure below to see the details. unittests/Object/CMakeFiles/ObjectTests.dir/OffloadingTest.cpp.oIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
jhuber6
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this in principle, but
jhuber6
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with these changes, now we just need the few changes to make sure that everything still works with the new version. Check all the uses of these fields and we probably want an obj2yaml support for multiple entries so we can test it. Realistically you just need to update the extractOffloadFiles to additionally extract files within the same header.
| uint64_t EntrySize; // Size of the metadata entry in bytes. | ||
| uint64_t Size; // Size in bytes of this entire binary. | ||
| uint64_t EntriesOffset; // Offset in bytes to the start of entries block. | ||
| uint64_t EntriesCount; // Number of metadata entries in the binary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with changing this, it wasn't really used for anything but a sanity check during parsing
Thank you for quick feedback, Joseph, I'll continue updating this PR with the further changes. |
|
FYI: I'm now updating |
Yeah, we'll probably just want to make the interface take an array reference, possibly a helper that takes a single one and turns it into an array of one for convenience |
jhuber6
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should keep the accessor methods to all take a single image, so the extract code just returns an array of these. You'd need to make sure the reference stays alive but it might be simpler that way, I don't think the interface handles this well, like for checking the image kind.
| OffloadKind getOffloadKind() const { return Entries[0].first->TheOffloadKind; } | ||
| uint32_t getVersion() const { return TheHeader->Version; } | ||
| uint32_t getFlags() const { return TheEntry->Flags; } | ||
| uint32_t getFlags() const { return Entries[0].first->Flags; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this has any users, we can and should change the interface
| StringRef getArch() const { return getString("arch"); } | ||
| StringRef getImage() const { | ||
| return StringRef(&Buffer[TheEntry->ImageOffset], TheEntry->ImageSize); | ||
| return StringRef(&Buffer[Entries[0].first->ImageOffset], Entries[0].first->ImageSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want an index, can initialize it to zero for backward compat.
| MapVector<StringRef, StringRef> StringData; | ||
| /// Location of the metadata entries within the binary mapped to | ||
| /// the key-value string data. | ||
| SmallVector<std::pair<const Entry *, StringMap>, 1> Entries; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't decide if this should be two vectors that take the same index
| const StringEntry *StringMapBegin = reinterpret_cast<const StringEntry *>( | ||
| &Buffer[TheEntry->StringOffset]); | ||
| StringMap Strings; | ||
| for (uint64_t SI = 0, SE = TheEntry->NumStrings; SI != SE; ++SI) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just take a reference to the StringData and keep the old handling?
No description provided.