================
@@ -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:

Why did we need to change this part? It's been awhile since I've looked at this 
but I'm assuming this violates the base class's expected interface.

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

Reply via email to