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
33 class ExecutionEngine {
39 // GlobalAddress - A mapping between LLVM global values and their actualized
41 std::map<const GlobalValue*, void *> GlobalAddress;
43 void setTargetData(const TargetData &td) {
48 ExecutionEngine(ModuleProvider *P);
49 ExecutionEngine(Module *M);
50 virtual ~ExecutionEngine();
52 Module &getModule() const { return CurMod; }
53 const TargetData &getTargetData() const { return *TD; }
55 /// run - Start execution with the specified function, arguments, and
58 virtual GenericValue run(Function *F,
59 const std::vector<GenericValue> &ArgValues) = 0;
61 static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter);
63 void addGlobalMapping(const Function *F, void *Addr) {
64 void *&CurVal = GlobalAddress[(const GlobalValue*)F];
65 assert(CurVal == 0 && "GlobalMapping already established!");
69 /// getPointerToGlobalIfAvailable - This returns the address of the specified
70 /// global value if it is available, otherwise it returns null.
72 void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
73 std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
74 return I != GlobalAddress.end() ? I->second : 0;
77 /// getPointerToGlobal - This returns the address of the specified global
78 /// value. This may involve code generation if it's a function.
80 void *getPointerToGlobal(const GlobalValue *GV);
82 /// getPointerToFunction - The different EE's represent function bodies in
83 /// different ways. They should each implement this to say what a function
84 /// pointer should look like.
86 virtual void *getPointerToFunction(Function *F) = 0;
88 /// getPointerToFunctionOrStub - If the specified function has been
89 /// code-gen'd, return a pointer to the function. If not, compile it, or use
90 /// a stub to implement lazy compilation if available.
92 virtual void *getPointerToFunctionOrStub(Function *F) {
93 // Default implementation, just codegen the function.
94 return getPointerToFunction(F);
97 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
98 void InitializeMemory(const Constant *Init, void *Addr);
100 /// recompileAndRelinkFunction - This method is used to force a function
101 /// which has already been compiled to be compiled again, possibly
102 /// after it has been modified. Then the entry to the old copy is overwritten
103 /// with a branch to the new copy. If there was no old copy, this acts
104 /// just like VM::getPointerToFunction().
106 virtual void *recompileAndRelinkFunction(Function *F) = 0;
110 GenericValue getConstantValue(const Constant *C);
111 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
114 } // End llvm namespace