================
@@ -161,28 +183,36 @@ class OffloadFile : public OwningBinary<OffloadBinary> {
using TargetID = std::pair<StringRef, StringRef>;
OffloadFile(std::unique_ptr<OffloadBinary> Binary,
- std::unique_ptr<MemoryBuffer> Buffer)
- : OwningBinary<OffloadBinary>(std::move(Binary), std::move(Buffer)) {}
+ std::shared_ptr<MemoryBuffer> SharedBuffer)
+ : OwningBinary<OffloadBinary>(std::move(Binary), nullptr),
+ SharedBuffer(std::move(SharedBuffer)) {}
- /// Make a deep copy of this offloading file.
- OffloadFile copy() const {
- std::unique_ptr<MemoryBuffer> Buffer = MemoryBuffer::getMemBufferCopy(
- getBinary()->getMemoryBufferRef().getBuffer(),
- getBinary()->getMemoryBufferRef().getBufferIdentifier());
+ /// Create a new OffloadFile with a new Binary but reuse SharedBuffer from
+ /// another OffloadFile.
+ OffloadFile(std::unique_ptr<OffloadBinary> Binary,
+ const OffloadFile &Other)
+ : OwningBinary<OffloadBinary>(std::move(Binary), nullptr),
+ SharedBuffer(Other.SharedBuffer) {}
+ /// Make a deep copy of this offloading file.
+ OffloadFile copy(uint64_t Index = 0) const {
// This parsing should never fail because it has already been parsed.
- auto NewBinaryOrErr = OffloadBinary::create(*Buffer);
+ auto NewBinaryOrErr =
OffloadBinary::create(MemoryBufferRef(*SharedBuffer), Index);
assert(NewBinaryOrErr && "Failed to parse a copy of the binary?");
if (!NewBinaryOrErr)
llvm::consumeError(NewBinaryOrErr.takeError());
- return OffloadFile(std::move(*NewBinaryOrErr), std::move(Buffer));
+ return OffloadFile(std::move(*NewBinaryOrErr), SharedBuffer);
}
/// We use the Triple and Architecture pair to group linker inputs together.
/// This conversion function lets us use these inputs in a hash-map.
operator TargetID() const {
return std::make_pair(getBinary()->getTriple(), getBinary()->getArch());
}
+
+private:
+ /// Shared buffer for binaries with multiple entries
+ std::shared_ptr<MemoryBuffer> SharedBuffer;
----------------
YuriPlyakhin wrote:
OffloadFile object is an owning binary containing actual memory buffer. It is
created for each OffloadBinary object currently (which contain a reference to
memory handled by OffloadFile object), so there is 1:1 relationship between
OffloadFile and OffloadBinary.
Do you suggest to have 1:N relationship between OffloadFile and OffloadBinary
then?
Or do you suggest to modify memory buffer to split it for each image so that
each memory buffer would actually contain: `Header, 1 Entry, set of
StringEntries for this one Entry,Strings for this one entry,1 Image` to not
duplicate the entire memory buffer between multiple OffloadFile objects?
https://github.com/llvm/llvm-project/pull/169425
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits