Added LLVM copyright header.
[oota-llvm.git] / lib / ExecutionEngine / JIT / VM.h
1 //===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the top-level Virtual Machine data structure.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef VM_H
15 #define VM_H
16
17 #include "llvm/ExecutionEngine/ExecutionEngine.h"
18 #include "llvm/PassManager.h"
19 #include <map>
20
21 class Function;
22 class GlobalValue;
23 class Constant;
24 class TargetMachine;
25 class MachineCodeEmitter;
26
27 class VM : public ExecutionEngine {
28   TargetMachine &TM;       // The current target we are compiling to
29   FunctionPassManager PM;  // Passes to compile a function
30   MachineCodeEmitter *MCE; // MCE object
31
32 public:
33   VM(ModuleProvider *MP, TargetMachine *tm);
34   ~VM();
35
36   /// create - Create an return a new JIT compiler if there is one available
37   /// for the current target.  Otherwise, return null.
38   ///
39   static ExecutionEngine *create(ModuleProvider *MP);
40
41   /// run - Start execution with the specified function and arguments.
42   ///
43   virtual GenericValue run(Function *F,
44                            const std::vector<GenericValue> &ArgValues);
45
46   /// getPointerToNamedFunction - This method returns the address of the
47   /// specified function by using the dlsym function call.  As such it is only
48   /// useful for resolving library symbols, not code generated symbols.
49   ///
50   void *getPointerToNamedFunction(const std::string &Name);
51
52   // CompilationCallback - Invoked the first time that a call site is found,
53   // which causes lazy compilation of the target function.
54   // 
55   static void CompilationCallback();
56
57   /// runAtExitHandlers - Before exiting the program, at_exit functions must be
58   /// called.  This method calls them.
59   ///
60   static void runAtExitHandlers();
61
62   /// getPointerToFunction - This returns the address of the specified function,
63   /// compiling it if necessary.
64   ///
65   void *getPointerToFunction(Function *F);
66
67   /// recompileAndRelinkFunction - This method is used to force a function
68   /// which has already been compiled, to be compiled again, possibly
69   /// after it has been modified. Then the entry to the old copy is overwritten
70   /// with a branch to the new copy. If there was no old copy, this acts
71   /// just like VM::getPointerToFunction().
72   ///
73   void *recompileAndRelinkFunction(Function *F);
74
75 private:
76   static MachineCodeEmitter *createEmitter(VM &V);
77   void setupPassManager();
78   void runJITOnFunction (Function *F);
79 };
80
81 #endif