1 //===-- JIT.h - Class definition for the JIT --------------------*- 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 JIT data structure.
12 //===----------------------------------------------------------------------===//
17 #include "llvm/ExecutionEngine/ExecutionEngine.h"
18 #include "llvm/PassManager.h"
28 class MachineCodeEmitter;
32 FunctionPassManager PM; // Passes to compile a function
34 /// PendingGlobals - Global variables which have had memory allocated for them
35 /// while a function was code generated, but which have not been initialized
37 std::vector<const GlobalVariable*> PendingGlobals;
40 JITState(ModuleProvider *MP) : PM(MP) {}
42 FunctionPassManager& getPM(const MutexGuard& locked) {
46 std::vector<const GlobalVariable*>& getPendingGlobals(const MutexGuard& locked) {
47 return PendingGlobals;
52 class JIT : public ExecutionEngine {
53 TargetMachine &TM; // The current target we are compiling to
54 TargetJITInfo &TJI; // The JITInfo for the target we are compiling to
55 MachineCodeEmitter *MCE; // MCE object
59 JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji);
63 static void Register() {
67 /// getJITInfo - Return the target JIT information structure.
69 TargetJITInfo &getJITInfo() const { return TJI; }
71 /// create - Create an return a new JIT compiler if there is one available
72 /// for the current target. Otherwise, return null. If the JIT is created
73 /// successfully, it takes responsibility for deleting the specified
74 /// IntrinsicLowering implementation.
76 static ExecutionEngine *create(ModuleProvider *MP, IntrinsicLowering *IL = 0);
78 /// run - Start execution with the specified function and arguments.
80 virtual GenericValue runFunction(Function *F,
81 const std::vector<GenericValue> &ArgValues);
83 /// getPointerToNamedFunction - This method returns the address of the
84 /// specified function by using the dlsym function call. As such it is only
85 /// useful for resolving library symbols, not code generated symbols.
87 void *getPointerToNamedFunction(const std::string &Name);
89 // CompilationCallback - Invoked the first time that a call site is found,
90 // which causes lazy compilation of the target function.
92 static void CompilationCallback();
94 /// getPointerToFunction - This returns the address of the specified function,
95 /// compiling it if necessary.
97 void *getPointerToFunction(Function *F);
99 /// getOrEmitGlobalVariable - Return the address of the specified global
100 /// variable, possibly emitting it to memory if needed. This is used by the
102 void *getOrEmitGlobalVariable(const GlobalVariable *GV);
104 /// getPointerToFunctionOrStub - If the specified function has been
105 /// code-gen'd, return a pointer to the function. If not, compile it, or use
106 /// a stub to implement lazy compilation if available.
108 void *getPointerToFunctionOrStub(Function *F);
110 /// recompileAndRelinkFunction - This method is used to force a function
111 /// which has already been compiled, to be compiled again, possibly
112 /// after it has been modified. Then the entry to the old copy is overwritten
113 /// with a branch to the new copy. If there was no old copy, this acts
114 /// just like JIT::getPointerToFunction().
116 void *recompileAndRelinkFunction(Function *F);
118 /// freeMachineCodeForFunction - deallocate memory used to code-generate this
121 void freeMachineCodeForFunction(Function *F);
124 static MachineCodeEmitter *createEmitter(JIT &J);
125 void runJITOnFunction (Function *F);
128 } // End llvm namespace