diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-19 18:44:46 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-19 18:44:46 +0000 |
| commit | 48af1c2a1a5148bc6a143bc0d8650ef744f2f7c3 (patch) | |
| tree | b702bea9017a8fb461da713a083af53f596b95ef /llvm/lib/ExecutionEngine/MCJIT | |
| parent | f17f03e00e5dc20f2cdbfbd4cc36e47a8966d2f7 (diff) | |
| download | bcm5719-llvm-48af1c2a1a5148bc6a143bc0d8650ef744f2f7c3.tar.gz bcm5719-llvm-48af1c2a1a5148bc6a143bc0d8650ef744f2f7c3.zip | |
Don't own the buffer in object::Binary.
Owning the buffer is somewhat inflexible. Some Binaries have sub Binaries
(like Archive) and we had to create dummy buffers just to handle that. It is
also a bad fit for IRObjectFile where the Module wants to own the buffer too.
Keeping this ownership would make supporting IR inside native objects
particularly painful.
This patch focuses in lib/Object. If something elsewhere used to own an Binary,
now it also owns a MemoryBuffer.
This patch introduces a few new types.
* MemoryBufferRef. This is just a pair of StringRefs for the data and name.
This is to MemoryBuffer as StringRef is to std::string.
* OwningBinary. A combination of Binary and a MemoryBuffer. This is needed
for convenience functions that take a filename and return both the
buffer and the Binary using that buffer.
The C api now uses OwningBinary to avoid any change in semantics. I will start
a new thread to see if we want to change it and how.
llvm-svn: 216002
Diffstat (limited to 'llvm/lib/ExecutionEngine/MCJIT')
| -rw-r--r-- | llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/MCJIT/MCJIT.h | 4 |
2 files changed, 7 insertions, 6 deletions
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 65e2aba29ee..9583fb2add6 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -119,7 +119,7 @@ void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) { NotifyObjectEmitted(*LoadedObject); } -void MCJIT::addArchive(std::unique_ptr<object::Archive> A) { +void MCJIT::addArchive(object::OwningBinary<object::Archive> A) { Archives.push_back(std::move(A)); } @@ -161,8 +161,8 @@ ObjectBufferStream* MCJIT::emitObject(Module *M) { if (ObjCache) { // MemoryBuffer is a thin wrapper around the actual memory, so it's OK // to create a temporary object here and delete it after the call. - std::unique_ptr<MemoryBuffer> MB = CompiledObject->getMemBuffer(); - ObjCache->notifyObjectCompiled(M, MB.get()); + MemoryBufferRef MB = CompiledObject->getMemBuffer(); + ObjCache->notifyObjectCompiled(M, MB); } return CompiledObject.release(); @@ -295,7 +295,8 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name, if (Addr) return Addr; - for (std::unique_ptr<object::Archive> &A : Archives) { + for (object::OwningBinary<object::Archive> &OB : Archives) { + object::Archive *A = OB.getBinary().get(); // Look for our symbols in each Archive object::Archive::child_iterator ChildIt = A->findSym(Name); if (ChildIt != A->child_end()) { diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h index 6a814db5ef2..4bf6d2939e7 100644 --- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h +++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h @@ -216,7 +216,7 @@ class MCJIT : public ExecutionEngine { OwningModuleContainer OwnedModules; - SmallVector<std::unique_ptr<object::Archive>, 2> Archives; + SmallVector<object::OwningBinary<object::Archive>, 2> Archives; typedef SmallVector<ObjectImage *, 2> LoadedObjectList; LoadedObjectList LoadedObjects; @@ -240,7 +240,7 @@ public: /// @{ void addModule(std::unique_ptr<Module> M) override; void addObjectFile(std::unique_ptr<object::ObjectFile> O) override; - void addArchive(std::unique_ptr<object::Archive> O) override; + void addArchive(object::OwningBinary<object::Archive> O) override; bool removeModule(Module *M) override; /// FindFunctionNamed - Search all of the active modules to find the one that |

