ExecutionEngine.h revision 7ed47a13356daed2a34cd2209a31f92552e3bdd8
1bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner//===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===// 2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 9bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// 10bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// This file defines the abstract interface that implements execution support 11bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// for LLVM. 12bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner// 13bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner//===----------------------------------------------------------------------===// 14bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 159f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner#ifndef LLVM_EXECUTION_ENGINE_H 169f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner#define LLVM_EXECUTION_ENGINE_H 17bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 18bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner#include <vector> 19bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner#include <map> 202e99791a1ed49f11a2825a9a7590742e1ddc110aChris Lattner#include <cassert> 2120aa474f8fbebde588edc101b90e834df28ce4ceAlkis Evlogimenos#include <string> 22683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner#include "llvm/System/Mutex.h" 23fe854034677f59baca1e38075e71f6efca247a03Chris Lattner#include "llvm/ADT/SmallVector.h" 24d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 25d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 279d87eb19be82b28d288e38eab3bbe145060a0701Reid Spencerstruct GenericValue; 28bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerclass Constant; 29bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerclass Function; 303ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattnerclass GlobalVariable; 31b6c54ed8f50a351989993a5ef88507abc6d63e2dMisha Brukmanclass GlobalValue; 32bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerclass Module; 337034adbce2fc7e761d745dbf586167380a69ee1aMisha Brukmanclass ModuleProvider; 34bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerclass TargetData; 35b6c54ed8f50a351989993a5ef88507abc6d63e2dMisha Brukmanclass Type; 36683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattnerclass MutexGuard; 379f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattnerclass JITMemoryManager; 38bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 39ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerclass ExecutionEngineState { 40ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerprivate: 41c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// GlobalAddressMap - A mapping between LLVM global values and their 42c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// actualized version... 43c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner std::map<const GlobalValue*, void *> GlobalAddressMap; 44c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner 45c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap, 46c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// used to convert raw addresses into the LLVM global value that is emitted 47c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// at the address. This map is not computed unless getGlobalValueAtAddress 48c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// is called at some point. 49c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner std::map<void *, const GlobalValue*> GlobalAddressReverseMap; 50ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 51ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerpublic: 52765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner std::map<const GlobalValue*, void *> & 53765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner getGlobalAddressMap(const MutexGuard &locked) { 54ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer return GlobalAddressMap; 55ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer } 56ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 57765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner std::map<void*, const GlobalValue*> & 58765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner getGlobalAddressReverseMap(const MutexGuard& locked) { 59ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer return GlobalAddressReverseMap; 60ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer } 61ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer}; 62ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 63ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 64ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencerclass ExecutionEngine { 65ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer const TargetData *TD; 66ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer ExecutionEngineState state; 671c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner bool LazyCompilationDisabled; 68d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner 691514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattnerprotected: 70fe854034677f59baca1e38075e71f6efca247a03Chris Lattner /// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We 71fe854034677f59baca1e38075e71f6efca247a03Chris Lattner /// use a smallvector to optimize for the case where there is only one module. 72fe854034677f59baca1e38075e71f6efca247a03Chris Lattner SmallVector<ModuleProvider*, 1> Modules; 73fe854034677f59baca1e38075e71f6efca247a03Chris Lattner 74a69571c7991813c93cba64e88eced6899ce93d81Owen Anderson void setTargetData(const TargetData *td) { 75a69571c7991813c93cba64e88eced6899ce93d81Owen Anderson TD = td; 76bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner } 77b6c54ed8f50a351989993a5ef88507abc6d63e2dMisha Brukman 78765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner // To avoid having libexecutionengine depend on the JIT and interpreter 79765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner // libraries, the JIT and Interpreter set these functions to ctor pointers 80765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner // at startup time if they are linked in. 81c923435a5953993c046b6259a8c4c0589e00b69fReid Spencer typedef ExecutionEngine *(*EECtorFn)(ModuleProvider*, std::string*); 82765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner static EECtorFn JITCtor, InterpCtor; 83d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner 84d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// LazyFunctionCreator - If an unknown function is needed, this function 85d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// pointer is invoked to create it. If this returns null, the JIT will abort. 86d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner void* (*LazyFunctionCreator)(const std::string &); 87d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner 88bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattnerpublic: 89765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner /// lock - This lock is protects the ExecutionEngine, JIT, JITResolver and 90765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner /// JITEmitter classes. It must be held while changing the internal state of 91765c93cefda367d8e5a8e0afcd610a7e15bbd987Chris Lattner /// any of those classes. 92ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer sys::Mutex lock; // Used to make this class and subclasses thread-safe 93ee448630bdf7eb6037fe2c50518d32010c433ca3Reid Spencer 949f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner //===----------------------------------------------------------------------===// 959f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner // ExecutionEngine Startup 969f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner //===----------------------------------------------------------------------===// 97ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman 989f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner virtual ~ExecutionEngine(); 99bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 1009f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner /// create - This is the factory method for creating an execution engine which 1019f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner /// is appropriate for the current machine. This takes ownership of the 1029f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner /// module provider. 1039f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner static ExecutionEngine *create(ModuleProvider *MP, 1049f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner bool ForceInterpreter = false, 1059f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner std::string *ErrorStr = 0); 1069f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 1079f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner /// create - This is the factory method for creating an execution engine which 1089f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner /// is appropriate for the current machine. This takes ownership of the 1099f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner /// module. 1109f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner static ExecutionEngine *create(Module *M); 11134c9433004cabd4760987dce4804a91c84908219Chris Lattner 11234c9433004cabd4760987dce4804a91c84908219Chris Lattner /// createJIT - This is the factory method for creating a JIT for the current 11334c9433004cabd4760987dce4804a91c84908219Chris Lattner /// machine, it does not fall back to the interpreter. This takes ownership 11434c9433004cabd4760987dce4804a91c84908219Chris Lattner /// of the ModuleProvider and JITMemoryManager if successful. 11534c9433004cabd4760987dce4804a91c84908219Chris Lattner static ExecutionEngine *createJIT(ModuleProvider *MP, 11634c9433004cabd4760987dce4804a91c84908219Chris Lattner std::string *ErrorStr = 0, 11734c9433004cabd4760987dce4804a91c84908219Chris Lattner JITMemoryManager *JMM = 0); 11834c9433004cabd4760987dce4804a91c84908219Chris Lattner 1199f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 1209f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 1212e40ae4de67ba37d02281d51e7dfd629205e1e30Chris Lattner /// addModuleProvider - Add a ModuleProvider to the list of modules that we 1222e40ae4de67ba37d02281d51e7dfd629205e1e30Chris Lattner /// can JIT from. Note that this takes ownership of the ModuleProvider: when 1232e40ae4de67ba37d02281d51e7dfd629205e1e30Chris Lattner /// the ExecutionEngine is destroyed, it destroys the MP as well. 1242e40ae4de67ba37d02281d51e7dfd629205e1e30Chris Lattner void addModuleProvider(ModuleProvider *P) { 1252e40ae4de67ba37d02281d51e7dfd629205e1e30Chris Lattner Modules.push_back(P); 1262e40ae4de67ba37d02281d51e7dfd629205e1e30Chris Lattner } 1279f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 1289f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner //===----------------------------------------------------------------------===// 1299f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 1309f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner const TargetData *getTargetData() const { return TD; } 1319f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 13273d0e211a39650fc7562e0f15ed21440dde2243aDevang Patel 13373d0e211a39650fc7562e0f15ed21440dde2243aDevang Patel /// removeModuleProvider - Remove a ModuleProvider from the list of modules. 13473d0e211a39650fc7562e0f15ed21440dde2243aDevang Patel /// Release module from ModuleProvider. 13573d0e211a39650fc7562e0f15ed21440dde2243aDevang Patel Module* removeModuleProvider(ModuleProvider *P, std::string *ErrInfo = 0); 13673d0e211a39650fc7562e0f15ed21440dde2243aDevang Patel 137fe854034677f59baca1e38075e71f6efca247a03Chris Lattner /// FindFunctionNamed - Search all of the active modules to find the one that 138fe854034677f59baca1e38075e71f6efca247a03Chris Lattner /// defines FnName. This is very slow operation and shouldn't be used for 139fe854034677f59baca1e38075e71f6efca247a03Chris Lattner /// general code. 140fe854034677f59baca1e38075e71f6efca247a03Chris Lattner Function *FindFunctionNamed(const char *FnName); 141fe854034677f59baca1e38075e71f6efca247a03Chris Lattner 142ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner /// runFunction - Execute the specified function with the specified arguments, 143ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner /// and return the result. 144ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner /// 145ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner virtual GenericValue runFunction(Function *F, 146ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner const std::vector<GenericValue> &ArgValues) = 0; 147ff65e36be0f4fbe776ee6bb39b7ab14ebe3895ebChris Lattner 1489ca6cdaee91fddcd3ea57dedcd624c14c7a40f65Chris Lattner /// runStaticConstructorsDestructors - This method is used to execute all of 1499ca6cdaee91fddcd3ea57dedcd624c14c7a40f65Chris Lattner /// the static constructors or destructors for a module, depending on the 1509ca6cdaee91fddcd3ea57dedcd624c14c7a40f65Chris Lattner /// value of isDtors. 1519ca6cdaee91fddcd3ea57dedcd624c14c7a40f65Chris Lattner void runStaticConstructorsDestructors(bool isDtors); 1529ca6cdaee91fddcd3ea57dedcd624c14c7a40f65Chris Lattner 1539ca6cdaee91fddcd3ea57dedcd624c14c7a40f65Chris Lattner 154e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner /// runFunctionAsMain - This is a helper function which wraps runFunction to 155e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner /// handle the common task of starting up main with the specified argc, argv, 156e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner /// and envp parameters. 157e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv, 158e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner const char * const * envp); 159e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner 160e5dbbf2bddf7fc28d9f63a5e978af12184c80adaChris Lattner 161683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// addGlobalMapping - Tell the execution engine that the specified global is 162683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// at the specified location. This is used internally as functions are JIT'd 163683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// and as global variables are laid out in memory. It can and should also be 164683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// used by clients of the EE that want to have an LLVM global overlay 165683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// existing data in memory. 166683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner void addGlobalMapping(const GlobalValue *GV, void *Addr); 167683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner 1680982d081056f64d7245ba26368d20de33e206ff9Reid Spencer /// clearAllGlobalMappings - Clear all global mappings and start over again 1690982d081056f64d7245ba26368d20de33e206ff9Reid Spencer /// use in dynamic compilation scenarios when you want to move globals 170683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner void clearAllGlobalMappings(); 171683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner 172f5feaf4fe381476b0ea567d7837c64b6590133e9Chris Lattner /// updateGlobalMapping - Replace an existing mapping for GV with a new 173683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// address. This updates both maps as required. If "Addr" is null, the 174683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// entry for the global is removed from the mappings. 175683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner void updateGlobalMapping(const GlobalValue *GV, void *Addr); 176683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner 177895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToGlobalIfAvailable - This returns the address of the specified 178683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// global value if it is has already been codegen'd, otherwise it returns 179683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner /// null. 180895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// 181683d1bb712d8f8fc2d727a160da029c9cf40a423Chris Lattner void *getPointerToGlobalIfAvailable(const GlobalValue *GV); 18270bca51f92871c7f9d3eac9ab68292c149fab53cChris Lattner 183895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToGlobal - This returns the address of the specified global 184895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// value. This may involve code generation if it's a function. 185895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// 186bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner void *getPointerToGlobal(const GlobalValue *GV); 187bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 188895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToFunction - The different EE's represent function bodies in 189895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// different ways. They should each implement this to say what a function 190895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// pointer should look like. 191895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// 192fb0ef2e82cb2e80983c097100ae168af68ee8e7bBrian Gaeke virtual void *getPointerToFunction(Function *F) = 0; 193bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 194895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// getPointerToFunctionOrStub - If the specified function has been 195895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// code-gen'd, return a pointer to the function. If not, compile it, or use 196895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// a stub to implement lazy compilation if available. 197895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// 19818cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner virtual void *getPointerToFunctionOrStub(Function *F) { 19918cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner // Default implementation, just codegen the function. 20018cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner return getPointerToFunction(F); 20118cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner } 20218cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner 203c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// getGlobalValueAtAddress - Return the LLVM global value object that starts 204c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// at the specified address. 205c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner /// 206c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner const GlobalValue *getGlobalValueAtAddress(void *Addr); 207c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner 208c8a07d7378699b8d11ce2a1549b984d84706da19Chris Lattner 2092471ae46df8f59a69cc152230f3f39d2e68525c5Reid Spencer void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, const Type *Ty); 21029794cba810ec249a9ede5ea77333a71579fd182Brian Gaeke void InitializeMemory(const Constant *Init, void *Addr); 21129794cba810ec249a9ede5ea77333a71579fd182Brian Gaeke 21218cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner /// recompileAndRelinkFunction - This method is used to force a function 213895be4bae2c4f9a2fd2234f0329f618274e67eabChris Lattner /// which has already been compiled to be compiled again, possibly 21418cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner /// after it has been modified. Then the entry to the old copy is overwritten 21518cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner /// with a branch to the new copy. If there was no old copy, this acts 21618cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner /// just like VM::getPointerToFunction(). 21718cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner /// 21818cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner virtual void *recompileAndRelinkFunction(Function *F) = 0; 21918cb4c3c747ac2439ca9fb1218edd8993df69d7aChris Lattner 220e81aaf238c32dbc34274ede09fb16aa78dae9f53Misha Brukman /// freeMachineCodeForFunction - Release memory in the ExecutionEngine 221e81aaf238c32dbc34274ede09fb16aa78dae9f53Misha Brukman /// corresponding to the machine code emitted to execute this function, useful 222e81aaf238c32dbc34274ede09fb16aa78dae9f53Misha Brukman /// for garbage-collecting generated code. 223e81aaf238c32dbc34274ede09fb16aa78dae9f53Misha Brukman /// 224e81aaf238c32dbc34274ede09fb16aa78dae9f53Misha Brukman virtual void freeMachineCodeForFunction(Function *F) = 0; 225e81aaf238c32dbc34274ede09fb16aa78dae9f53Misha Brukman 2261514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner /// getOrEmitGlobalVariable - Return the address of the specified global 2271514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner /// variable, possibly emitting it to memory if needed. This is used by the 2281514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner /// Emitter. 2291514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) { 2301514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner return getPointerToGlobal((GlobalValue*)GV); 2311514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner } 2321c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner 2331c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner /// DisableLazyCompilation - If called, the JIT will abort if lazy compilation 2341c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner // is ever attempted. 2351c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner void DisableLazyCompilation() { 2361c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner LazyCompilationDisabled = true; 2371c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner } 2381c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner bool isLazyCompilationDisabled() const { 2391c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner return LazyCompilationDisabled; 2401c1a44699049cf56713a46ccaef7c747e4a888a3Chris Lattner } 241d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner 242d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner 243d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// InstallLazyFunctionCreator - If an unknown function is needed, the 244d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// specified function pointer is invoked to create it. If it returns null, 245d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner /// the JIT will abort. 246d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner void InstallLazyFunctionCreator(void* (*P)(const std::string &)) { 247d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner LazyFunctionCreator = P; 248d958a5a9feea7239a73c2068f43f237db550f46eChris Lattner } 2491514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner 25056adf152f6354a9b5609e059050fd2315ad5960cChris Lattnerprotected: 251ded2b0d0fb0d4fa09198e3d05da529d2c97214c3Dan Gohman explicit ExecutionEngine(ModuleProvider *P); 2529f2f142d255bc96f109dd5c6524a485937b1f3a1Chris Lattner 253bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner void emitGlobals(); 2543ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattner 2553ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattner // EmitGlobalVariable - This method emits the specified global variable to the 2563ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattner // address specified in GlobalAddresses, or allocates new memory if it's not 2573ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattner // already in the map. 2581514b5b334c72e1e190fe1ce2bce7bf7d8a91c1aChris Lattner void EmitGlobalVariable(const GlobalVariable *GV); 2593ddc05bdde6ed65f93340ea467d362e80c0ceb9cChris Lattner 260bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner GenericValue getConstantValue(const Constant *C); 26147567bdcb5ba3886eaf3fa5f0e0b912a24c12347Reid Spencer void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, 26247567bdcb5ba3886eaf3fa5f0e0b912a24c12347Reid Spencer const Type *Ty); 263bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner}; 264bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner 265d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 266d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 267bd199fb1148b9e16c4e6f3d0ee386c2505a55b71Chris Lattner#endif 268