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/RuntimeDyld.h"
16 #include "llvm/PassManager.h"
22 // FIXME: This makes all kinds of horrible assumptions for the time being,
23 // like only having one module, not needing to worry about multi-threading,
24 // blah blah. Purely in get-it-up-and-limping mode for now.
26 class MCJIT : public ExecutionEngine {
27 MCJIT(Module *M, TargetMachine *tm, RTDyldMemoryManager *MemMgr,
28 bool AllocateGVsWithCode);
32 RTDyldMemoryManager *MemMgr;
34 SmallVector<JITEventListener*, 2> EventListeners;
36 // FIXME: Add support for multiple modules
39 OwningPtr<ObjectImage> LoadedObject;
44 /// @name ExecutionEngine interface implementation
47 virtual void finalizeObject();
49 virtual void *getPointerToBasicBlock(BasicBlock *BB);
51 virtual void *getPointerToFunction(Function *F);
53 virtual void *recompileAndRelinkFunction(Function *F);
55 virtual void freeMachineCodeForFunction(Function *F);
57 virtual GenericValue runFunction(Function *F,
58 const std::vector<GenericValue> &ArgValues);
60 /// getPointerToNamedFunction - This method returns the address of the
61 /// specified function by using the dlsym function call. As such it is only
62 /// useful for resolving library symbols, not code generated symbols.
64 /// If AbortOnFailure is false and no function with the given name is
65 /// found, this function silently returns a null pointer. Otherwise,
66 /// it prints a message to stderr and aborts.
68 virtual void *getPointerToNamedFunction(const std::string &Name,
69 bool AbortOnFailure = true);
71 /// mapSectionAddress - map a section to its target address space value.
72 /// Map the address of a JIT section as returned from the memory manager
73 /// to the address in the target process as the running code will see it.
74 /// This is the address which will be used for relocation resolution.
75 virtual void mapSectionAddress(const void *LocalAddress,
76 uint64_t TargetAddress) {
77 Dyld.mapSectionAddress(LocalAddress, TargetAddress);
80 virtual void RegisterJITEventListener(JITEventListener *L);
81 virtual void UnregisterJITEventListener(JITEventListener *L);
84 /// @name (Private) Registration Interfaces
87 static void Register() {
88 MCJITCtor = createJIT;
91 static ExecutionEngine *createJIT(Module *M,
92 std::string *ErrorStr,
93 JITMemoryManager *JMM,
100 /// emitObject -- Generate a JITed object in memory from the specified module
101 /// Currently, MCJIT only supports a single module and the module passed to
102 /// this function call is expected to be the contained module. The module
103 /// is passed as a parameter here to prepare for multiple module support in
105 void emitObject(Module *M);
107 void NotifyObjectEmitted(const ObjectImage& Obj);
108 void NotifyFreeingObject(const ObjectImage& Obj);
111 } // End llvm namespace