1 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- 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 abstract interface that implements execution support
13 //===----------------------------------------------------------------------===//
15 #ifndef EXECUTION_ENGINE_H
16 #define EXECUTION_ENGINE_H
34 class ExecutionEngine {
38 // GlobalAddress - A mapping between LLVM global values and their actualized
40 std::map<const GlobalValue*, void *> GlobalAddress;
44 void setTargetData(const TargetData &td) {
49 ExecutionEngine(ModuleProvider *P);
50 ExecutionEngine(Module *M);
51 virtual ~ExecutionEngine();
53 Module &getModule() const { return CurMod; }
54 const TargetData &getTargetData() const { return *TD; }
56 /// create - This is the factory method for creating an execution engine which
57 /// is appropriate for the current machine.
58 static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter);
60 /// runFunction - Execute the specified function with the specified arguments,
61 /// and return the result.
63 virtual GenericValue runFunction(Function *F,
64 const std::vector<GenericValue> &ArgValues) = 0;
66 void addGlobalMapping(const GlobalValue *GV, void *Addr) {
67 void *&CurVal = GlobalAddress[GV];
68 assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!");
72 /// getPointerToGlobalIfAvailable - This returns the address of the specified
73 /// global value if it is available, otherwise it returns null.
75 void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
76 std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
77 return I != GlobalAddress.end() ? I->second : 0;
80 /// getPointerToGlobal - This returns the address of the specified global
81 /// value. This may involve code generation if it's a function.
83 void *getPointerToGlobal(const GlobalValue *GV);
85 /// getPointerToFunction - The different EE's represent function bodies in
86 /// different ways. They should each implement this to say what a function
87 /// pointer should look like.
89 virtual void *getPointerToFunction(Function *F) = 0;
91 /// getPointerToFunctionOrStub - If the specified function has been
92 /// code-gen'd, return a pointer to the function. If not, compile it, or use
93 /// a stub to implement lazy compilation if available.
95 virtual void *getPointerToFunctionOrStub(Function *F) {
96 // Default implementation, just codegen the function.
97 return getPointerToFunction(F);
100 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
101 void InitializeMemory(const Constant *Init, void *Addr);
103 /// recompileAndRelinkFunction - This method is used to force a function
104 /// which has already been compiled to be compiled again, possibly
105 /// after it has been modified. Then the entry to the old copy is overwritten
106 /// with a branch to the new copy. If there was no old copy, this acts
107 /// just like VM::getPointerToFunction().
109 virtual void *recompileAndRelinkFunction(Function *F) = 0;
111 /// getOrEmitGlobalVariable - Return the address of the specified global
112 /// variable, possibly emitting it to memory if needed. This is used by the
114 virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
115 return getPointerToGlobal((GlobalValue*)GV);
121 // EmitGlobalVariable - This method emits the specified global variable to the
122 // address specified in GlobalAddresses, or allocates new memory if it's not
123 // already in the map.
124 void EmitGlobalVariable(const GlobalVariable *GV);
126 GenericValue getConstantValue(const Constant *C);
127 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
130 } // End llvm namespace