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 {
40 // GlobalAddress - A mapping between LLVM global values and their actualized
42 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 /// run - Start execution with the specified function, arguments, and
59 virtual GenericValue run(Function *F,
60 const std::vector<GenericValue> &ArgValues) = 0;
62 static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter);
64 void addGlobalMapping(const GlobalValue *GV, void *Addr) {
65 void *&CurVal = GlobalAddress[GV];
66 assert(CurVal == 0 && "GlobalMapping already established!");
70 /// getPointerToGlobalIfAvailable - This returns the address of the specified
71 /// global value if it is available, otherwise it returns null.
73 void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
74 std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
75 return I != GlobalAddress.end() ? I->second : 0;
78 /// getPointerToGlobal - This returns the address of the specified global
79 /// value. This may involve code generation if it's a function.
81 void *getPointerToGlobal(const GlobalValue *GV);
83 /// getPointerToFunction - The different EE's represent function bodies in
84 /// different ways. They should each implement this to say what a function
85 /// pointer should look like.
87 virtual void *getPointerToFunction(Function *F) = 0;
89 /// getPointerToFunctionOrStub - If the specified function has been
90 /// code-gen'd, return a pointer to the function. If not, compile it, or use
91 /// a stub to implement lazy compilation if available.
93 virtual void *getPointerToFunctionOrStub(Function *F) {
94 // Default implementation, just codegen the function.
95 return getPointerToFunction(F);
98 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
99 void InitializeMemory(const Constant *Init, void *Addr);
101 /// recompileAndRelinkFunction - This method is used to force a function
102 /// which has already been compiled to be compiled again, possibly
103 /// after it has been modified. Then the entry to the old copy is overwritten
104 /// with a branch to the new copy. If there was no old copy, this acts
105 /// just like VM::getPointerToFunction().
107 virtual void *recompileAndRelinkFunction(Function *F) = 0;
112 // EmitGlobalVariable - This method emits the specified global variable to the
113 // address specified in GlobalAddresses, or allocates new memory if it's not
114 // already in the map.
115 void EmitGlobalVariable(GlobalVariable *GV);
117 GenericValue getConstantValue(const Constant *C);
118 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
121 } // End llvm namespace