Hi, All I m not sure if this question has been asked or not. I'd like cache the MCJIT compiled object into memory buffer so it can be reused later. I followed the Andy Kaylor's example wrote an inherited class from ObjectCache and use raw_fd_ostream to save the cache and load the cache from a file. I checked raw_ostream and its subclass, maybe I am wrong but I don't see one is fit to save to memory buffer. Any suggestions? Thank you very much -- Best regards Cheng -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140917/5988b479/attachment.html>
Lang Hames
2014-Sep-18 17:43 UTC
[LLVMdev] How to cache MCJIT compiled object into memory?
Hi Cheng, You could use a raw_svector_ostream to write to a memory buffer, but that's unnecessarily complicated. You just need to clone the memory buffer pointed to by Obj. Something along the lines of: class MyCache : public ObjectCache { public: void notifyObjectCompiled(const Module *M, MemoryBufferRef Obj) override { CachedObjs[M] MemoryBuffer::getMemBufferCopy(Obj.getBuffer(), Obj.getBufferIdentifier()); } std::unique_ptr<MemoryBuffer> getObject(const Module *M) override { MemoryBuffer& B = *CachedObjs[M]; return MemoryBuffer::getMemBufferCopy(B.getBuffer(), B.getBufferIdentifier()); } private: std::map<Module*, std::unique_ptr<MemoryBuffer>> CachedObjs; }; Cheers, Lang. On Wed, Sep 17, 2014 at 6:18 PM, Cheng Zhu <chengzhu at gmail.com> wrote:> Hi, All > > I m not sure if this question has been asked or not. I'd like cache the > MCJIT compiled object into memory buffer so it can be reused later. I > followed the Andy Kaylor's example wrote an inherited class from > ObjectCache and use raw_fd_ostream to save the cache and load the cache > from a file. I checked raw_ostream and its subclass, maybe I am wrong but I > don't see one is fit to save to memory buffer. Any suggestions? > > Thank you very much > > -- > Best regards > > Cheng > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140918/598380bb/attachment.html>
Thank you Lang. That should work. I was planing to use llvm::StringRef as the value of the CacheObjs map, and use function name string as key earlier. I guess that should work too and less storage use right? On Thu, Sep 18, 2014 at 10:43 AM, Lang Hames <lhames at gmail.com> wrote:> Hi Cheng, > > You could use a raw_svector_ostream to write to a memory buffer, but > that's unnecessarily complicated. You just need to clone the memory buffer > pointed to by Obj. Something along the lines of: > > class MyCache : public ObjectCache { > public: > void notifyObjectCompiled(const Module *M, MemoryBufferRef Obj) override > { > CachedObjs[M] > MemoryBuffer::getMemBufferCopy(Obj.getBuffer(), > Obj.getBufferIdentifier()); > } > > std::unique_ptr<MemoryBuffer> getObject(const Module *M) override { > MemoryBuffer& B = *CachedObjs[M]; > return MemoryBuffer::getMemBufferCopy(B.getBuffer(), > B.getBufferIdentifier()); > } > > private: > std::map<Module*, std::unique_ptr<MemoryBuffer>> CachedObjs; > }; > > > Cheers, > Lang. > > > On Wed, Sep 17, 2014 at 6:18 PM, Cheng Zhu <chengzhu at gmail.com> wrote: > >> Hi, All >> >> I m not sure if this question has been asked or not. I'd like cache the >> MCJIT compiled object into memory buffer so it can be reused later. I >> followed the Andy Kaylor's example wrote an inherited class from >> ObjectCache and use raw_fd_ostream to save the cache and load the cache >> from a file. I checked raw_ostream and its subclass, maybe I am wrong but I >> don't see one is fit to save to memory buffer. Any suggestions? >> >> Thank you very much >> >> -- >> Best regards >> >> Cheng >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-- Best regards Cheng -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140918/f2d53421/attachment.html>
Maybe Matching Threads
- ObjectCache and getFunctionAddress issue
- [LLVMdev] Fail to load a pointer to a function inside MCJIT-ed code when it is reload from ObjectCache
- [LLVMdev] Fail to load a pointer to a function inside MCJIT-ed code when it is reload from ObjectCache
- [LLVMdev] [RFC] llvm/include/Support/OutputBuffer.h
- [LLVMdev] [RFC] llvm/include/Support/OutputBuffer.h