LLVM API Documentation
00001 //===-- JIT.h - Class definition for the JIT --------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the top-level JIT data structure. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef JIT_H 00015 #define JIT_H 00016 00017 #include "llvm/ExecutionEngine/ExecutionEngine.h" 00018 #include "llvm/PassManager.h" 00019 #include <map> 00020 00021 namespace llvm { 00022 00023 class Function; 00024 class GlobalValue; 00025 class Constant; 00026 class TargetMachine; 00027 class TargetJITInfo; 00028 class MachineCodeEmitter; 00029 00030 class JIT : public ExecutionEngine { 00031 TargetMachine &TM; // The current target we are compiling to 00032 TargetJITInfo &TJI; // The JITInfo for the target we are compiling to 00033 00034 FunctionPassManager PM; // Passes to compile a function 00035 MachineCodeEmitter *MCE; // MCE object 00036 00037 /// PendingGlobals - Global variables which have had memory allocated for them 00038 /// while a function was code generated, but which have not been initialized 00039 /// yet. 00040 std::vector<const GlobalVariable*> PendingGlobals; 00041 00042 JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji); 00043 public: 00044 ~JIT(); 00045 00046 /// getJITInfo - Return the target JIT information structure. 00047 /// 00048 TargetJITInfo &getJITInfo() const { return TJI; } 00049 00050 /// create - Create an return a new JIT compiler if there is one available 00051 /// for the current target. Otherwise, return null. If the JIT is created 00052 /// successfully, it takes responsibility for deleting the specified 00053 /// IntrinsicLowering implementation. 00054 /// 00055 static ExecutionEngine *create(ModuleProvider *MP, IntrinsicLowering *IL = 0); 00056 00057 /// run - Start execution with the specified function and arguments. 00058 /// 00059 virtual GenericValue runFunction(Function *F, 00060 const std::vector<GenericValue> &ArgValues); 00061 00062 /// getPointerToNamedFunction - This method returns the address of the 00063 /// specified function by using the dlsym function call. As such it is only 00064 /// useful for resolving library symbols, not code generated symbols. 00065 /// 00066 void *getPointerToNamedFunction(const std::string &Name); 00067 00068 // CompilationCallback - Invoked the first time that a call site is found, 00069 // which causes lazy compilation of the target function. 00070 // 00071 static void CompilationCallback(); 00072 00073 /// getPointerToFunction - This returns the address of the specified function, 00074 /// compiling it if necessary. 00075 /// 00076 void *getPointerToFunction(Function *F); 00077 00078 /// getOrEmitGlobalVariable - Return the address of the specified global 00079 /// variable, possibly emitting it to memory if needed. This is used by the 00080 /// Emitter. 00081 void *getOrEmitGlobalVariable(const GlobalVariable *GV); 00082 00083 /// getPointerToFunctionOrStub - If the specified function has been 00084 /// code-gen'd, return a pointer to the function. If not, compile it, or use 00085 /// a stub to implement lazy compilation if available. 00086 /// 00087 void *getPointerToFunctionOrStub(Function *F); 00088 00089 /// recompileAndRelinkFunction - This method is used to force a function 00090 /// which has already been compiled, to be compiled again, possibly 00091 /// after it has been modified. Then the entry to the old copy is overwritten 00092 /// with a branch to the new copy. If there was no old copy, this acts 00093 /// just like JIT::getPointerToFunction(). 00094 /// 00095 void *recompileAndRelinkFunction(Function *F); 00096 00097 /// freeMachineCodeForFunction - deallocate memory used to code-generate this 00098 /// Function. 00099 /// 00100 void freeMachineCodeForFunction(Function *F); 00101 00102 private: 00103 static MachineCodeEmitter *createEmitter(JIT &J); 00104 void runJITOnFunction (Function *F); 00105 }; 00106 00107 } // End llvm namespace 00108 00109 #endif