remove the intrinsiclowering hook
[oota-llvm.git] / lib / ExecutionEngine / JIT / JIT.h
1 //===-- JIT.h - Class definition for the JIT --------------------*- 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 JIT data structure.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef JIT_H
15 #define JIT_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 TargetJITInfo;
28 class MachineCodeEmitter;
29
30 class JITState {
31 private:
32   FunctionPassManager PM;  // Passes to compile a function
33
34   /// PendingGlobals - Global variables which have had memory allocated for them
35   /// while a function was code generated, but which have not been initialized
36   /// yet.
37   std::vector<const GlobalVariable*> PendingGlobals;
38
39 public:
40   JITState(ModuleProvider *MP) : PM(MP) {}
41
42   FunctionPassManager& getPM(const MutexGuard& locked) {
43     return PM;
44   }
45
46   std::vector<const GlobalVariable*>& getPendingGlobals(const MutexGuard& locked) {
47     return PendingGlobals;
48   }
49 };
50
51
52 class JIT : public ExecutionEngine {
53   TargetMachine &TM;       // The current target we are compiling to
54   TargetJITInfo &TJI;      // The JITInfo for the target we are compiling to
55   MachineCodeEmitter *MCE; // MCE object
56
57   JITState state;
58
59   JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji);
60 public:
61   ~JIT();
62
63   static void Register() {
64     JITCtor = create;
65   }
66   
67   /// getJITInfo - Return the target JIT information structure.
68   ///
69   TargetJITInfo &getJITInfo() const { return TJI; }
70
71   /// create - Create an return a new JIT compiler if there is one available
72   /// for the current target.  Otherwise, return null.
73   ///
74   static ExecutionEngine *create(ModuleProvider *MP);
75
76   /// run - Start execution with the specified function and arguments.
77   ///
78   virtual GenericValue runFunction(Function *F,
79                                    const std::vector<GenericValue> &ArgValues);
80
81   /// getPointerToNamedFunction - This method returns the address of the
82   /// specified function by using the dlsym function call.  As such it is only
83   /// useful for resolving library symbols, not code generated symbols.
84   ///
85   void *getPointerToNamedFunction(const std::string &Name);
86
87   // CompilationCallback - Invoked the first time that a call site is found,
88   // which causes lazy compilation of the target function.
89   //
90   static void CompilationCallback();
91
92   /// getPointerToFunction - This returns the address of the specified function,
93   /// compiling it if necessary.
94   ///
95   void *getPointerToFunction(Function *F);
96
97   /// getOrEmitGlobalVariable - Return the address of the specified global
98   /// variable, possibly emitting it to memory if needed.  This is used by the
99   /// Emitter.
100   void *getOrEmitGlobalVariable(const GlobalVariable *GV);
101
102   /// getPointerToFunctionOrStub - If the specified function has been
103   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
104   /// a stub to implement lazy compilation if available.
105   ///
106   void *getPointerToFunctionOrStub(Function *F);
107
108   /// recompileAndRelinkFunction - This method is used to force a function
109   /// which has already been compiled, to be compiled again, possibly
110   /// after it has been modified. Then the entry to the old copy is overwritten
111   /// with a branch to the new copy. If there was no old copy, this acts
112   /// just like JIT::getPointerToFunction().
113   ///
114   void *recompileAndRelinkFunction(Function *F);
115
116   /// freeMachineCodeForFunction - deallocate memory used to code-generate this
117   /// Function.
118   ///
119   void freeMachineCodeForFunction(Function *F);
120
121 private:
122   static MachineCodeEmitter *createEmitter(JIT &J);
123   void runJITOnFunction (Function *F);
124 };
125
126 } // End llvm namespace
127
128 #endif