14 #ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
15 #define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
34 typedef std::function<object::OwningBinary<object::ObjectFile>(
Module &)>
38 typedef typename BaseLayerT::ObjSetHandleT ObjSetHandleT;
40 typedef std::vector<std::unique_ptr<object::ObjectFile>> OwningObjectVec;
41 typedef std::vector<std::unique_ptr<MemoryBuffer>> OwningBufferVec;
50 : BaseLayer(BaseLayer), Compile(std::move(Compile)), ObjCache(nullptr) {}
60 template <
typename ModuleSetT,
typename MemoryManagerPtrT,
61 typename SymbolResolverPtrT>
63 MemoryManagerPtrT MemMgr,
64 SymbolResolverPtrT Resolver) {
65 OwningObjectVec Objects;
66 OwningBufferVec Buffers;
68 for (
const auto &M : Ms) {
69 std::unique_ptr<object::ObjectFile> Object;
70 std::unique_ptr<MemoryBuffer> Buffer;
73 std::tie(Object, Buffer) = tryToLoadFromObjectCache(*M).takeBinary();
76 std::tie(Object, Buffer) = Compile(*M).takeBinary();
81 Objects.push_back(std::move(Object));
82 Buffers.push_back(std::move(Buffer));
86 BaseLayer.addObjectSet(Objects, std::move(MemMgr), std::move(Resolver));
88 BaseLayer.takeOwnershipOfBuffers(H, std::move(Buffers));
101 return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
113 bool ExportedSymbolsOnly) {
114 return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
121 BaseLayer.emitAndFinalize(H);
126 tryToLoadFromObjectCache(
const Module &M) {
127 std::unique_ptr<MemoryBuffer> ObjBuffer = ObjCache->
getObject(&M);
137 std::move(ObjBuffer));
140 BaseLayerT &BaseLayer;
148 #endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILINGLAYER_H
Represents either an error or a value T.
A Module instance is used to store all the information related to an LLVM module. ...
virtual std::unique_ptr< MemoryBuffer > getObject(const Module *M)=0
Returns a pointer to a newly allocated MemoryBuffer that contains the object which corresponds with M...
ObjSetHandleT ModuleSetHandleT
Handle to a set of compiled modules.
IRCompileLayer(BaseLayerT &BaseLayer, CompileFtor Compile)
Construct an IRCompileLayer with the given BaseLayer, which must implement the ObjectLayer concept...
void setObjectCache(ObjectCache *NewCache)
Set an ObjectCache to query before compiling.
JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly)
Search for the given named symbol.
Eager IR compiling layer.
Represents a symbol in the JIT.
std::function< object::OwningBinary< object::ObjectFile >Module &)> CompileFtor
ModuleSetHandleT addModuleSet(ModuleSetT Ms, MemoryManagerPtrT MemMgr, SymbolResolverPtrT Resolver)
Compile each module in the given module set, then add the resulting set of objects to the base layer ...
virtual void notifyObjectCompiled(const Module *M, MemoryBufferRef Obj)=0
notifyObjectCompiled - Provides a pointer to compiled code for Module M.
void emitAndFinalize(ModuleSetHandleT H)
Immediately emit and finalize the moduleOB set represented by the given handle.
void removeModuleSet(ModuleSetHandleT H)
Remove the module set associated with the handle H.
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name, bool ExportedSymbolsOnly)
Get the address of the given symbol in the context of the set of compiled modules represented by the ...
This is the base ObjectCache type which can be provided to an ExecutionEngine for the purpose of avoi...
static ErrorOr< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.