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"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/Support/raw_ostream.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, TargetJITInfo &tji,
27 RTDyldMemoryManager *MemMgr, bool AllocateGVsWithCode);
31 RTDyldMemoryManager *MemMgr;
33 // FIXME: These may need moved to a separate 'jitstate' member like the
34 // non-MC JIT does for multithreading and such. Just keep them here for now.
37 // FIXME: This really doesn't belong here.
38 SmallVector<char, 4096> Buffer; // Working buffer into which we JIT.
39 raw_svector_ostream OS;
46 /// @name ExecutionEngine interface implementation
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);
70 /// mapSectionAddress - map a section to its target address space value.
71 /// Map the address of a JIT section as returned from the memory manager
72 /// to the address in the target process as the running code will see it.
73 /// This is the address which will be used for relocation resolution.
74 virtual void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress) {
75 Dyld.mapSectionAddress(LocalAddress, TargetAddress);
79 /// @name (Private) Registration Interfaces
82 static void Register() {
83 MCJITCtor = createJIT;
86 static ExecutionEngine *createJIT(Module *M,
87 std::string *ErrorStr,
88 JITMemoryManager *JMM,
95 } // End llvm namespace