JIT.h revision 9722294d30fff2a432d8e171eb904f33956353e2
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(Module *M, 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(Module *M);
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  void *getPointerToFunction(Function *F);
58
59private:
60  static MachineCodeEmitter *createEmitter(VM &V);
61  void setupPassManager();
62};
63
64#endif
65