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"
27 class MachineCodeEmitter;
29 class VM : public ExecutionEngine {
30 TargetMachine &TM; // The current target we are compiling to
31 FunctionPassManager PM; // Passes to compile a function
32 MachineCodeEmitter *MCE; // MCE object
35 VM(ModuleProvider *MP, TargetMachine *tm);
38 /// create - Create an return a new JIT compiler if there is one available
39 /// for the current target. Otherwise, return null.
41 static ExecutionEngine *create(ModuleProvider *MP);
43 /// run - Start execution with the specified function and arguments.
45 virtual GenericValue run(Function *F,
46 const std::vector<GenericValue> &ArgValues);
48 /// getPointerToNamedFunction - This method returns the address of the
49 /// specified function by using the dlsym function call. As such it is only
50 /// useful for resolving library symbols, not code generated symbols.
52 void *getPointerToNamedFunction(const std::string &Name);
54 // CompilationCallback - Invoked the first time that a call site is found,
55 // which causes lazy compilation of the target function.
57 static void CompilationCallback();
59 /// runAtExitHandlers - Before exiting the program, at_exit functions must be
60 /// called. This method calls them.
62 static void runAtExitHandlers();
64 /// getPointerToFunction - This returns the address of the specified function,
65 /// compiling it if necessary.
67 void *getPointerToFunction(Function *F);
69 /// recompileAndRelinkFunction - This method is used to force a function
70 /// which has already been compiled, to be compiled again, possibly
71 /// after it has been modified. Then the entry to the old copy is overwritten
72 /// with a branch to the new copy. If there was no old copy, this acts
73 /// just like VM::getPointerToFunction().
75 void *recompileAndRelinkFunction(Function *F);
78 static MachineCodeEmitter *createEmitter(VM &V);
79 void setupPassManager();
80 void runJITOnFunction (Function *F);
83 } // End llvm namespace