Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 1 | //===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===// |
John Criswell | 856ba76 | 2003-10-21 15:17:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines the top-level Virtual Machine data structure. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef VM_H |
| 15 | #define VM_H |
| 16 | |
Brian Gaeke | 9722294 | 2003-09-05 19:39:22 +0000 | [diff] [blame] | 17 | #include "llvm/ExecutionEngine/ExecutionEngine.h" |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 18 | #include "llvm/PassManager.h" |
| 19 | #include <map> |
| 20 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | namespace llvm { |
| 22 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 23 | class Function; |
| 24 | class GlobalValue; |
| 25 | class Constant; |
| 26 | class TargetMachine; |
| 27 | class MachineCodeEmitter; |
| 28 | |
| 29 | class VM : public ExecutionEngine { |
| 30 | TargetMachine &TM; // The current target we are compiling to |
Brian Gaeke | c227c1f | 2003-08-13 18:16:50 +0000 | [diff] [blame] | 31 | FunctionPassManager PM; // Passes to compile a function |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 32 | MachineCodeEmitter *MCE; // MCE object |
| 33 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 34 | public: |
Misha Brukman | 005e5e9 | 2003-10-14 21:37:41 +0000 | [diff] [blame] | 35 | VM(ModuleProvider *MP, TargetMachine *tm); |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 36 | ~VM(); |
| 37 | |
Brian Gaeke | 82d8277 | 2003-09-03 20:34:19 +0000 | [diff] [blame] | 38 | /// create - Create an return a new JIT compiler if there is one available |
| 39 | /// for the current target. Otherwise, return null. |
| 40 | /// |
Misha Brukman | 005e5e9 | 2003-10-14 21:37:41 +0000 | [diff] [blame] | 41 | static ExecutionEngine *create(ModuleProvider *MP); |
Brian Gaeke | 82d8277 | 2003-09-03 20:34:19 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 43 | /// run - Start execution with the specified function and arguments. |
| 44 | /// |
Brian Gaeke | 70975ee | 2003-09-05 18:42:01 +0000 | [diff] [blame] | 45 | virtual GenericValue run(Function *F, |
| 46 | const std::vector<GenericValue> &ArgValues); |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 0d448c0 | 2003-01-13 01:00:48 +0000 | [diff] [blame] | 48 | /// getPointerToNamedFunction - This method returns the address of the |
| 49 | /// specified function by using the dlsym function call. As such it is only |
| 50 | /// useful for resolving library symbols, not code generated symbols. |
| 51 | /// |
| 52 | void *getPointerToNamedFunction(const std::string &Name); |
| 53 | |
Chris Lattner | c309a76 | 2003-05-08 21:34:11 +0000 | [diff] [blame] | 54 | // CompilationCallback - Invoked the first time that a call site is found, |
| 55 | // which causes lazy compilation of the target function. |
| 56 | // |
| 57 | static void CompilationCallback(); |
Chris Lattner | 22080f9 | 2003-05-14 13:53:40 +0000 | [diff] [blame] | 58 | |
| 59 | /// runAtExitHandlers - Before exiting the program, at_exit functions must be |
| 60 | /// called. This method calls them. |
| 61 | /// |
| 62 | static void runAtExitHandlers(); |
| 63 | |
Chris Lattner | bba1b6d | 2003-06-01 23:24:36 +0000 | [diff] [blame] | 64 | /// getPointerToFunction - This returns the address of the specified function, |
| 65 | /// compiling it if necessary. |
Brian Gaeke | 55c0f02 | 2003-10-17 18:27:12 +0000 | [diff] [blame] | 66 | /// |
Brian Gaeke | c227c1f | 2003-08-13 18:16:50 +0000 | [diff] [blame] | 67 | void *getPointerToFunction(Function *F); |
Chris Lattner | bba1b6d | 2003-06-01 23:24:36 +0000 | [diff] [blame] | 68 | |
Chris Lattner | 993bdce | 2003-12-12 07:12:02 +0000 | [diff] [blame^] | 69 | /// getPointerToFunctionOrStub - If the specified function has been |
| 70 | /// code-gen'd, return a pointer to the function. If not, compile it, or use |
| 71 | /// a stub to implement lazy compilation if available. |
| 72 | /// |
| 73 | void *getPointerToFunctionOrStub(Function *F); |
| 74 | |
Brian Gaeke | 55c0f02 | 2003-10-17 18:27:12 +0000 | [diff] [blame] | 75 | /// recompileAndRelinkFunction - This method is used to force a function |
| 76 | /// which has already been compiled, to be compiled again, possibly |
| 77 | /// after it has been modified. Then the entry to the old copy is overwritten |
| 78 | /// with a branch to the new copy. If there was no old copy, this acts |
| 79 | /// just like VM::getPointerToFunction(). |
| 80 | /// |
| 81 | void *recompileAndRelinkFunction(Function *F); |
| 82 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 83 | private: |
Misha Brukman | 906f5fa | 2003-06-02 03:23:16 +0000 | [diff] [blame] | 84 | static MachineCodeEmitter *createEmitter(VM &V); |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 85 | void setupPassManager(); |
Brian Gaeke | 55c0f02 | 2003-10-17 18:27:12 +0000 | [diff] [blame] | 86 | void runJITOnFunction (Function *F); |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 89 | } // End llvm namespace |
| 90 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 91 | #endif |