1 //===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines the top-level Virtual Machine data structure.
12 //===----------------------------------------------------------------------===//
17 #include "llvm/ExecutionEngine/ExecutionEngine.h"
18 #include "llvm/PassManager.h"
28 class MachineCodeEmitter;
30 class VM : public ExecutionEngine {
31 TargetMachine &TM; // The current target we are compiling to
32 TargetJITInfo &TJI; // The JITInfo for the target we are compiling to
34 FunctionPassManager PM; // Passes to compile a function
35 MachineCodeEmitter *MCE; // MCE object
37 VM(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji);
41 /// create - Create an return a new JIT compiler if there is one available
42 /// for the current target. Otherwise, return null.
44 static ExecutionEngine *create(ModuleProvider *MP);
46 /// run - Start execution with the specified function and arguments.
48 virtual GenericValue run(Function *F,
49 const std::vector<GenericValue> &ArgValues);
51 /// getPointerToNamedFunction - This method returns the address of the
52 /// specified function by using the dlsym function call. As such it is only
53 /// useful for resolving library symbols, not code generated symbols.
55 void *getPointerToNamedFunction(const std::string &Name);
57 // CompilationCallback - Invoked the first time that a call site is found,
58 // which causes lazy compilation of the target function.
60 static void CompilationCallback();
62 /// runAtExitHandlers - Before exiting the program, at_exit functions must be
63 /// called. This method calls them.
65 static void runAtExitHandlers();
67 /// getPointerToFunction - This returns the address of the specified function,
68 /// compiling it if necessary.
70 void *getPointerToFunction(Function *F);
72 /// getPointerToFunctionOrStub - If the specified function has been
73 /// code-gen'd, return a pointer to the function. If not, compile it, or use
74 /// a stub to implement lazy compilation if available.
76 void *getPointerToFunctionOrStub(Function *F);
78 /// recompileAndRelinkFunction - This method is used to force a function
79 /// which has already been compiled, to be compiled again, possibly
80 /// after it has been modified. Then the entry to the old copy is overwritten
81 /// with a branch to the new copy. If there was no old copy, this acts
82 /// just like VM::getPointerToFunction().
84 void *recompileAndRelinkFunction(Function *F);
87 static MachineCodeEmitter *createEmitter(VM &V);
88 void setupPassManager();
89 void runJITOnFunction (Function *F);
92 } // End llvm namespace