================
@@ -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;
----------------
jhuber6 wrote:
The offload binaries already contain references to externally handled memory, I
don't think this changes that contract at all. You just have one bit of
external memory that's bound to several objects. If we want to create an owning
binary then we probably just need to do a deep copy, basically creating a new
single element offload file in my mind.
https://github.com/llvm/llvm-project/pull/169425
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits