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