LLVM API Documentation
00001 //===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_H 00011 #define LLVM_LIB_EXECUTIONENGINE_MCJIT_H 00012 00013 #include "llvm/PassManager.h" 00014 #include "llvm/ExecutionEngine/ExecutionEngine.h" 00015 #include "llvm/ExecutionEngine/RuntimeDyld.h" 00016 #include "llvm/ADT/SmallVector.h" 00017 #include "llvm/Support/raw_ostream.h" 00018 00019 namespace llvm { 00020 00021 // FIXME: This makes all kinds of horrible assumptions for the time being, 00022 // like only having one module, not needing to worry about multi-threading, 00023 // blah blah. Purely in get-it-up-and-limping mode for now. 00024 00025 class MCJIT : public ExecutionEngine { 00026 MCJIT(Module *M, TargetMachine *tm, TargetJITInfo &tji, 00027 RTDyldMemoryManager *MemMgr, bool AllocateGVsWithCode); 00028 00029 TargetMachine *TM; 00030 MCContext *Ctx; 00031 RTDyldMemoryManager *MemMgr; 00032 00033 // FIXME: These may need moved to a separate 'jitstate' member like the 00034 // non-MC JIT does for multithreading and such. Just keep them here for now. 00035 PassManager PM; 00036 Module *M; 00037 // FIXME: This really doesn't belong here. 00038 SmallVector<char, 4096> Buffer; // Working buffer into which we JIT. 00039 raw_svector_ostream OS; 00040 00041 RuntimeDyld Dyld; 00042 00043 public: 00044 ~MCJIT(); 00045 00046 /// @name ExecutionEngine interface implementation 00047 /// @{ 00048 00049 virtual void *getPointerToBasicBlock(BasicBlock *BB); 00050 00051 virtual void *getPointerToFunction(Function *F); 00052 00053 virtual void *recompileAndRelinkFunction(Function *F); 00054 00055 virtual void freeMachineCodeForFunction(Function *F); 00056 00057 virtual GenericValue runFunction(Function *F, 00058 const std::vector<GenericValue> &ArgValues); 00059 00060 /// getPointerToNamedFunction - This method returns the address of the 00061 /// specified function by using the dlsym function call. As such it is only 00062 /// useful for resolving library symbols, not code generated symbols. 00063 /// 00064 /// If AbortOnFailure is false and no function with the given name is 00065 /// found, this function silently returns a null pointer. Otherwise, 00066 /// it prints a message to stderr and aborts. 00067 /// 00068 virtual void *getPointerToNamedFunction(const std::string &Name, 00069 bool AbortOnFailure = true); 00070 00071 /// mapSectionAddress - map a section to its target address space value. 00072 /// Map the address of a JIT section as returned from the memory manager 00073 /// to the address in the target process as the running code will see it. 00074 /// This is the address which will be used for relocation resolution. 00075 virtual void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress) { 00076 Dyld.mapSectionAddress(LocalAddress, TargetAddress); 00077 } 00078 00079 /// @} 00080 /// @name (Private) Registration Interfaces 00081 /// @{ 00082 00083 static void Register() { 00084 MCJITCtor = createJIT; 00085 } 00086 00087 static ExecutionEngine *createJIT(Module *M, 00088 std::string *ErrorStr, 00089 JITMemoryManager *JMM, 00090 bool GVsWithCode, 00091 TargetMachine *TM); 00092 00093 // @} 00094 }; 00095 00096 } // End llvm namespace 00097 00098 #endif