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;
30 class JIT : 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 /// PendingGlobals - Global variables which have had memory allocated for them
38 /// while a function was code generated, but which have not been initialized
40 std::vector<const GlobalVariable*> PendingGlobals;
42 JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji);
46 /// create - Create an return a new JIT compiler if there is one available
47 /// for the current target. Otherwise, return null. If the JIT is created
48 /// successfully, it takes responsibility for deleting the specified
49 /// IntrinsicLowering implementation.
51 static ExecutionEngine *create(ModuleProvider *MP, IntrinsicLowering *IL = 0);
53 /// run - Start execution with the specified function and arguments.
55 virtual GenericValue runFunction(Function *F,
56 const std::vector<GenericValue> &ArgValues);
58 /// getPointerToNamedFunction - This method returns the address of the
59 /// specified function by using the dlsym function call. As such it is only
60 /// useful for resolving library symbols, not code generated symbols.
62 void *getPointerToNamedFunction(const std::string &Name);
64 // CompilationCallback - Invoked the first time that a call site is found,
65 // which causes lazy compilation of the target function.
67 static void CompilationCallback();
69 /// getPointerToFunction - This returns the address of the specified function,
70 /// compiling it if necessary.
72 void *getPointerToFunction(Function *F);
74 /// getOrEmitGlobalVariable - Return the address of the specified global
75 /// variable, possibly emitting it to memory if needed. This is used by the
77 void *getOrEmitGlobalVariable(const GlobalVariable *GV);
79 /// getPointerToFunctionOrStub - If the specified function has been
80 /// code-gen'd, return a pointer to the function. If not, compile it, or use
81 /// a stub to implement lazy compilation if available.
83 void *getPointerToFunctionOrStub(Function *F);
85 /// recompileAndRelinkFunction - This method is used to force a function
86 /// which has already been compiled, to be compiled again, possibly
87 /// after it has been modified. Then the entry to the old copy is overwritten
88 /// with a branch to the new copy. If there was no old copy, this acts
89 /// just like JIT::getPointerToFunction().
91 void *recompileAndRelinkFunction(Function *F);
93 /// freeMachineCodeForFunction - deallocate memory used to code-generate this
96 void freeMachineCodeForFunction(Function *F);
99 static MachineCodeEmitter *createEmitter(JIT &J);
100 void runJITOnFunction (Function *F);
103 } // End llvm namespace