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