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