| LEFT | RIGHT |
| 1 //===-- JIT.h - Class definition for the JIT --------------------*- C++ -*-===// | 1 //===-- JIT.h - Class definition for the JIT --------------------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file defines the top-level JIT data structure. | 10 // This file defines the top-level JIT data structure. |
| 11 // | 11 // |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 #ifndef JIT_H | 14 #ifndef JIT_H |
| 15 #define JIT_H | 15 #define JIT_H |
| 16 | 16 |
| 17 #include "llvm/ExecutionEngine/ExecutionEngine.h" | 17 #include "llvm/ExecutionEngine/ExecutionEngine.h" |
| 18 #include "llvm/PassManager.h" | 18 #include "llvm/PassManager.h" |
| 19 | 19 |
| 20 namespace llvm { | 20 namespace llvm { |
| 21 | 21 |
| 22 class Function; | 22 class Function; |
| 23 class JITEvent_EmittedFunctionDetails; | 23 struct JITEvent_EmittedFunctionDetails; |
| 24 class MachineCodeEmitter; | 24 class MachineCodeEmitter; |
| 25 class MachineCodeInfo; | 25 class MachineCodeInfo; |
| 26 class TargetJITInfo; | 26 class TargetJITInfo; |
| 27 class TargetMachine; | 27 class TargetMachine; |
| 28 | 28 |
| 29 class JITState { | 29 class JITState { |
| 30 private: | 30 private: |
| 31 FunctionPassManager PM; // Passes to compile a function | 31 FunctionPassManager PM; // Passes to compile a function |
| 32 ModuleProvider *MP; // ModuleProvider used to create the PM | 32 ModuleProvider *MP; // ModuleProvider used to create the PM |
| 33 | 33 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 48 } | 48 } |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 | 51 |
| 52 class JIT : public ExecutionEngine { | 52 class JIT : public ExecutionEngine { |
| 53 TargetMachine &TM; // The current target we are compiling to | 53 TargetMachine &TM; // The current target we are compiling to |
| 54 TargetJITInfo &TJI; // The JITInfo for the target we are compiling to | 54 TargetJITInfo &TJI; // The JITInfo for the target we are compiling to |
| 55 JITCodeEmitter *JCE; // JCE object | 55 JITCodeEmitter *JCE; // JCE object |
| 56 std::vector<JITEventListener*> EventListeners; | 56 std::vector<JITEventListener*> EventListeners; |
| 57 | 57 |
| 58 /// AllocateGVsWithCode - Some applications require that global variables and |
| 59 /// code be allocated into the same region of memory, in which case this flag |
| 60 /// should be set to true. Doing so breaks freeMachineCodeForFunction. |
| 61 bool AllocateGVsWithCode; |
| 62 |
| 58 JITState *jitstate; | 63 JITState *jitstate; |
| 59 | 64 |
| 60 JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji, | 65 JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji, |
| 61 JITMemoryManager *JMM, CodeGenOpt::Level OptLevel); | 66 JITMemoryManager *JMM, CodeGenOpt::Level OptLevel, |
| 67 bool AllocateGVsWithCode); |
| 62 public: | 68 public: |
| 63 ~JIT(); | 69 ~JIT(); |
| 64 | 70 |
| 65 static void Register() { | 71 static void Register() { |
| 66 JITCtor = create; | 72 JITCtor = create; |
| 67 } | 73 } |
| 68 | 74 |
| 69 /// getJITInfo - Return the target JIT information structure. | 75 /// getJITInfo - Return the target JIT information structure. |
| 70 /// | 76 /// |
| 71 TargetJITInfo &getJITInfo() const { return TJI; } | 77 TargetJITInfo &getJITInfo() const { return TJI; } |
| 72 | 78 |
| 73 /// create - Create an return a new JIT compiler if there is one available | 79 /// create - Create an return a new JIT compiler if there is one available |
| 74 /// for the current target. Otherwise, return null. | 80 /// for the current target. Otherwise, return null. |
| 75 /// | 81 /// |
| 76 static ExecutionEngine *create(ModuleProvider *MP, std::string *Err, | 82 static ExecutionEngine *create(ModuleProvider *MP, |
| 83 std::string *Err, |
| 84 JITMemoryManager *JMM, |
| 77 CodeGenOpt::Level OptLevel = | 85 CodeGenOpt::Level OptLevel = |
| 78 CodeGenOpt::Default) { | 86 CodeGenOpt::Default, |
| 79 return createJIT(MP, Err, 0, OptLevel); | 87 bool GVsWithCode = true) { |
| 88 return ExecutionEngine::createJIT(MP, Err, JMM, OptLevel, GVsWithCode); |
| 80 } | 89 } |
| 81 | 90 |
| 82 virtual void addModuleProvider(ModuleProvider *MP); | 91 virtual void addModuleProvider(ModuleProvider *MP); |
| 83 | 92 |
| 84 /// removeModuleProvider - Remove a ModuleProvider from the list of modules. | 93 /// removeModuleProvider - Remove a ModuleProvider from the list of modules. |
| 85 /// Relases the Module from the ModuleProvider, materializing it in the | 94 /// Relases the Module from the ModuleProvider, materializing it in the |
| 86 /// process, and returns the materialized Module. | 95 /// process, and returns the materialized Module. |
| 87 virtual Module *removeModuleProvider(ModuleProvider *MP, | 96 virtual Module *removeModuleProvider(ModuleProvider *MP, |
| 88 std::string *ErrInfo = 0); | 97 std::string *ErrInfo = 0); |
| 89 | 98 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 void *recompileAndRelinkFunction(Function *F); | 147 void *recompileAndRelinkFunction(Function *F); |
| 139 | 148 |
| 140 /// freeMachineCodeForFunction - deallocate memory used to code-generate this | 149 /// freeMachineCodeForFunction - deallocate memory used to code-generate this |
| 141 /// Function. | 150 /// Function. |
| 142 /// | 151 /// |
| 143 void freeMachineCodeForFunction(Function *F); | 152 void freeMachineCodeForFunction(Function *F); |
| 144 | 153 |
| 145 /// addPendingFunction - while jitting non-lazily, a called but non-codegen'd | 154 /// addPendingFunction - while jitting non-lazily, a called but non-codegen'd |
| 146 /// function was encountered. Add it to a pending list to be processed after | 155 /// function was encountered. Add it to a pending list to be processed after |
| 147 /// the current function. | 156 /// the current function. |
| 148 /// | 157 /// |
| 149 void addPendingFunction(Function *F); | 158 void addPendingFunction(Function *F); |
| 150 | 159 |
| 151 /// getCodeEmitter - Return the code emitter this JIT is emitting into. | 160 /// getCodeEmitter - Return the code emitter this JIT is emitting into. |
| 161 /// |
| 152 JITCodeEmitter *getCodeEmitter() const { return JCE; } | 162 JITCodeEmitter *getCodeEmitter() const { return JCE; } |
| 153 | 163 |
| 154 static ExecutionEngine *createJIT(ModuleProvider *MP, std::string *Err, | 164 /// selectTarget - Pick a target either via -march or by guessing the native |
| 165 /// arch. Add any CPU features specified via -mcpu or -mattr. |
| 166 static TargetMachine *selectTarget(ModuleProvider *MP, std::string *Err); |
| 167 |
| 168 static ExecutionEngine *createJIT(ModuleProvider *MP, |
| 169 std::string *ErrorStr, |
| 155 JITMemoryManager *JMM, | 170 JITMemoryManager *JMM, |
| 156 CodeGenOpt::Level OptLevel); | 171 CodeGenOpt::Level OptLevel, |
| 157 | 172 bool GVsWithCode); |
| 158 | 173 |
| 159 // Run the JIT on F and return information about the generated code | 174 // Run the JIT on F and return information about the generated code |
| 160 void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0); | 175 void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0); |
| 161 | 176 |
| 162 virtual void RegisterJITEventListener(JITEventListener *L); | 177 virtual void RegisterJITEventListener(JITEventListener *L); |
| 163 virtual void UnregisterJITEventListener(JITEventListener *L); | 178 virtual void UnregisterJITEventListener(JITEventListener *L); |
| 164 /// These functions correspond to the methods on JITEventListener. They | 179 /// These functions correspond to the methods on JITEventListener. They |
| 165 /// iterate over the registered listeners and call the corresponding method on | 180 /// iterate over the registered listeners and call the corresponding method on |
| 166 /// each. | 181 /// each. |
| 167 void NotifyFunctionEmitted( | 182 void NotifyFunctionEmitted( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 protected: | 194 protected: |
| 180 | 195 |
| 181 /// getMemoryforGV - Allocate memory for a global variable. | 196 /// getMemoryforGV - Allocate memory for a global variable. |
| 182 virtual char* getMemoryForGV(const GlobalVariable* GV); | 197 virtual char* getMemoryForGV(const GlobalVariable* GV); |
| 183 | 198 |
| 184 }; | 199 }; |
| 185 | 200 |
| 186 } // End llvm namespace | 201 } // End llvm namespace |
| 187 | 202 |
| 188 #endif | 203 #endif |
| LEFT | RIGHT |