1 //===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_H
11 #define LLVM_LIB_EXECUTIONENGINE_MCJIT_H
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ExecutionEngine/ExecutionEngine.h"
15 #include "llvm/ExecutionEngine/ObjectCache.h"
16 #include "llvm/ExecutionEngine/RuntimeDyld.h"
17 #include "llvm/PassManager.h"
23 // FIXME: This makes all kinds of horrible assumptions for the time being,
24 // like only having one module, not needing to worry about multi-threading,
25 // blah blah. Purely in get-it-up-and-limping mode for now.
27 class MCJIT : public ExecutionEngine {
28 MCJIT(Module *M, TargetMachine *tm, RTDyldMemoryManager *MemMgr,
29 bool AllocateGVsWithCode);
33 RTDyldMemoryManager *MemMgr;
35 SmallVector<JITEventListener*, 2> EventListeners;
37 // FIXME: Add support for multiple modules
40 OwningPtr<ObjectImage> LoadedObject;
42 // An optional ObjectCache to be notified of compiled objects and used to
43 // perform lookup of pre-compiled code to avoid re-compilation.
44 ObjectCache *ObjCache;
49 /// @name ExecutionEngine interface implementation
52 /// Sets the object manager that MCJIT should use to avoid compilation.
53 virtual void setObjectCache(ObjectCache *manager);
55 virtual void finalizeObject();
57 virtual void *getPointerToBasicBlock(BasicBlock *BB);
59 virtual void *getPointerToFunction(Function *F);
61 virtual void *recompileAndRelinkFunction(Function *F);
63 virtual void freeMachineCodeForFunction(Function *F);
65 virtual GenericValue runFunction(Function *F,
66 const std::vector<GenericValue> &ArgValues);
68 /// getPointerToNamedFunction - This method returns the address of the
69 /// specified function by using the dlsym function call. As such it is only
70 /// useful for resolving library symbols, not code generated symbols.
72 /// If AbortOnFailure is false and no function with the given name is
73 /// found, this function silently returns a null pointer. Otherwise,
74 /// it prints a message to stderr and aborts.
76 virtual void *getPointerToNamedFunction(const std::string &Name,
77 bool AbortOnFailure = true);
79 /// mapSectionAddress - map a section to its target address space value.
80 /// Map the address of a JIT section as returned from the memory manager
81 /// to the address in the target process as the running code will see it.
82 /// This is the address which will be used for relocation resolution.
83 virtual void mapSectionAddress(const void *LocalAddress,
84 uint64_t TargetAddress) {
85 Dyld.mapSectionAddress(LocalAddress, TargetAddress);
88 virtual void RegisterJITEventListener(JITEventListener *L);
89 virtual void UnregisterJITEventListener(JITEventListener *L);
92 /// @name (Private) Registration Interfaces
95 static void Register() {
96 MCJITCtor = createJIT;
99 static ExecutionEngine *createJIT(Module *M,
100 std::string *ErrorStr,
101 JITMemoryManager *JMM,
108 /// emitObject -- Generate a JITed object in memory from the specified module
109 /// Currently, MCJIT only supports a single module and the module passed to
110 /// this function call is expected to be the contained module. The module
111 /// is passed as a parameter here to prepare for multiple module support in
113 ObjectBufferStream* emitObject(Module *M);
115 void loadObject(Module *M);
117 void NotifyObjectEmitted(const ObjectImage& Obj);
118 void NotifyFreeingObject(const ObjectImage& Obj);
121 } // End llvm namespace