Put all LLVM code into the llvm namespace, as per bug 109.
[oota-llvm.git] / lib / ExecutionEngine / JIT / JIT.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 namespace llvm {
22
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
31   FunctionPassManager PM;  // Passes to compile a function
32   MachineCodeEmitter *MCE; // MCE object
33
34 public:
35   VM(ModuleProvider *MP, TargetMachine *tm);
36   ~VM();
37
38   /// create - Create an return a new JIT compiler if there is one available
39   /// for the current target.  Otherwise, return null.
40   ///
41   static ExecutionEngine *create(ModuleProvider *MP);
42
43   /// run - Start execution with the specified function and arguments.
44   ///
45   virtual GenericValue run(Function *F,
46                            const std::vector<GenericValue> &ArgValues);
47
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
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();
58
59   /// runAtExitHandlers - Before exiting the program, at_exit functions must be
60   /// called.  This method calls them.
61   ///
62   static void runAtExitHandlers();
63
64   /// getPointerToFunction - This returns the address of the specified function,
65   /// compiling it if necessary.
66   ///
67   void *getPointerToFunction(Function *F);
68
69   /// recompileAndRelinkFunction - This method is used to force a function
70   /// which has already been compiled, to be compiled again, possibly
71   /// after it has been modified. Then the entry to the old copy is overwritten
72   /// with a branch to the new copy. If there was no old copy, this acts
73   /// just like VM::getPointerToFunction().
74   ///
75   void *recompileAndRelinkFunction(Function *F);
76
77 private:
78   static MachineCodeEmitter *createEmitter(VM &V);
79   void setupPassManager();
80   void runJITOnFunction (Function *F);
81 };
82
83 } // End llvm namespace
84
85 #endif