ExecutionEngine.h revision 198892
1193323Sed//===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file defines the abstract interface that implements execution support 11193323Sed// for LLVM. 12193323Sed// 13193323Sed//===----------------------------------------------------------------------===// 14193323Sed 15193323Sed#ifndef LLVM_EXECUTION_ENGINE_H 16193323Sed#define LLVM_EXECUTION_ENGINE_H 17193323Sed 18193323Sed#include <vector> 19193323Sed#include <map> 20193323Sed#include <string> 21193323Sed#include "llvm/ADT/SmallVector.h" 22198892Srdivacky#include "llvm/ADT/ValueMap.h" 23198090Srdivacky#include "llvm/Support/ValueHandle.h" 24193323Sed#include "llvm/System/Mutex.h" 25193323Sed#include "llvm/Target/TargetMachine.h" 26193323Sed 27193323Sednamespace llvm { 28193323Sed 29193323Sedstruct GenericValue; 30193323Sedclass Constant; 31198090Srdivackyclass ExecutionEngine; 32193323Sedclass Function; 33193323Sedclass GlobalVariable; 34193323Sedclass GlobalValue; 35195098Sedclass JITEventListener; 36195098Sedclass JITMemoryManager; 37195098Sedclass MachineCodeInfo; 38193323Sedclass Module; 39193323Sedclass ModuleProvider; 40195098Sedclass MutexGuard; 41193323Sedclass TargetData; 42193323Sedclass Type; 43193323Sed 44193323Sedclass ExecutionEngineState { 45198090Srdivackypublic: 46198892Srdivacky struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> { 47198892Srdivacky typedef ExecutionEngineState *ExtraData; 48198892Srdivacky static sys::Mutex *getMutex(ExecutionEngineState *EES); 49198892Srdivacky static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old); 50198892Srdivacky static void onRAUW(ExecutionEngineState *, const GlobalValue *, 51198892Srdivacky const GlobalValue *); 52198892Srdivacky }; 53198090Srdivacky 54198892Srdivacky typedef ValueMap<const GlobalValue *, void *, AddressMapConfig> 55198892Srdivacky GlobalAddressMapTy; 56198090Srdivacky 57193323Sedprivate: 58198090Srdivacky ExecutionEngine &EE; 59198090Srdivacky 60193323Sed /// GlobalAddressMap - A mapping between LLVM global values and their 61193323Sed /// actualized version... 62198892Srdivacky GlobalAddressMapTy GlobalAddressMap; 63193323Sed 64193323Sed /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap, 65193323Sed /// used to convert raw addresses into the LLVM global value that is emitted 66193323Sed /// at the address. This map is not computed unless getGlobalValueAtAddress 67193323Sed /// is called at some point. 68198090Srdivacky std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap; 69193323Sed 70193323Sedpublic: 71198892Srdivacky ExecutionEngineState(ExecutionEngine &EE); 72198090Srdivacky 73198892Srdivacky GlobalAddressMapTy & 74193323Sed getGlobalAddressMap(const MutexGuard &) { 75193323Sed return GlobalAddressMap; 76193323Sed } 77193323Sed 78198090Srdivacky std::map<void*, AssertingVH<const GlobalValue> > & 79193323Sed getGlobalAddressReverseMap(const MutexGuard &) { 80193323Sed return GlobalAddressReverseMap; 81193323Sed } 82198090Srdivacky 83198090Srdivacky // Returns the address ToUnmap was mapped to. 84198090Srdivacky void *RemoveMapping(const MutexGuard &, const GlobalValue *ToUnmap); 85193323Sed}; 86193323Sed 87193323Sed 88193323Sedclass ExecutionEngine { 89193323Sed const TargetData *TD; 90198090Srdivacky ExecutionEngineState EEState; 91198892Srdivacky bool CompilingLazily; 92193323Sed bool GVCompilationDisabled; 93193323Sed bool SymbolSearchingDisabled; 94193323Sed bool DlsymStubsEnabled; 95193323Sed 96198090Srdivacky friend class EngineBuilder; // To allow access to JITCtor and InterpCtor. 97198090Srdivacky 98193323Sedprotected: 99193323Sed /// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We 100193323Sed /// use a smallvector to optimize for the case where there is only one module. 101193323Sed SmallVector<ModuleProvider*, 1> Modules; 102193323Sed 103193323Sed void setTargetData(const TargetData *td) { 104193323Sed TD = td; 105193323Sed } 106193323Sed 107193323Sed /// getMemoryforGV - Allocate memory for a global variable. 108193323Sed virtual char* getMemoryForGV(const GlobalVariable* GV); 109193323Sed 110193323Sed // To avoid having libexecutionengine depend on the JIT and interpreter 111193323Sed // libraries, the JIT and Interpreter set these functions to ctor pointers 112193323Sed // at startup time if they are linked in. 113198090Srdivacky static ExecutionEngine *(*JITCtor)(ModuleProvider *MP, 114198090Srdivacky std::string *ErrorStr, 115198090Srdivacky JITMemoryManager *JMM, 116198090Srdivacky CodeGenOpt::Level OptLevel, 117198090Srdivacky bool GVsWithCode); 118198090Srdivacky static ExecutionEngine *(*InterpCtor)(ModuleProvider *MP, 119198090Srdivacky std::string *ErrorStr); 120193323Sed 121193323Sed /// LazyFunctionCreator - If an unknown function is needed, this function 122193323Sed /// pointer is invoked to create it. If this returns null, the JIT will abort. 123193323Sed void* (*LazyFunctionCreator)(const std::string &); 124193323Sed 125193323Sed /// ExceptionTableRegister - If Exception Handling is set, the JIT will 126193323Sed /// register dwarf tables with this function 127193323Sed typedef void (*EERegisterFn)(void*); 128193323Sed static EERegisterFn ExceptionTableRegister; 129193323Sed 130193323Sedpublic: 131193323Sed /// lock - This lock is protects the ExecutionEngine, JIT, JITResolver and 132193323Sed /// JITEmitter classes. It must be held while changing the internal state of 133193323Sed /// any of those classes. 134193323Sed sys::Mutex lock; // Used to make this class and subclasses thread-safe 135193323Sed 136193323Sed //===--------------------------------------------------------------------===// 137193323Sed // ExecutionEngine Startup 138193323Sed //===--------------------------------------------------------------------===// 139193323Sed 140193323Sed virtual ~ExecutionEngine(); 141193323Sed 142193323Sed /// create - This is the factory method for creating an execution engine which 143193323Sed /// is appropriate for the current machine. This takes ownership of the 144193323Sed /// module provider. 145193323Sed static ExecutionEngine *create(ModuleProvider *MP, 146193323Sed bool ForceInterpreter = false, 147193323Sed std::string *ErrorStr = 0, 148193323Sed CodeGenOpt::Level OptLevel = 149198090Srdivacky CodeGenOpt::Default, 150198090Srdivacky // Allocating globals with code breaks 151198090Srdivacky // freeMachineCodeForFunction and is probably 152198090Srdivacky // unsafe and bad for performance. However, 153198090Srdivacky // we have clients who depend on this 154198090Srdivacky // behavior, so we must support it. 155198090Srdivacky // Eventually, when we're willing to break 156198090Srdivacky // some backwards compatability, this flag 157198090Srdivacky // should be flipped to false, so that by 158198090Srdivacky // default freeMachineCodeForFunction works. 159198090Srdivacky bool GVsWithCode = true); 160198090Srdivacky 161193323Sed /// create - This is the factory method for creating an execution engine which 162193323Sed /// is appropriate for the current machine. This takes ownership of the 163193323Sed /// module. 164193323Sed static ExecutionEngine *create(Module *M); 165193323Sed 166193323Sed /// createJIT - This is the factory method for creating a JIT for the current 167193323Sed /// machine, it does not fall back to the interpreter. This takes ownership 168193323Sed /// of the ModuleProvider and JITMemoryManager if successful. 169198090Srdivacky /// 170198090Srdivacky /// Clients should make sure to initialize targets prior to calling this 171198090Srdivacky /// function. 172193323Sed static ExecutionEngine *createJIT(ModuleProvider *MP, 173193323Sed std::string *ErrorStr = 0, 174193323Sed JITMemoryManager *JMM = 0, 175193323Sed CodeGenOpt::Level OptLevel = 176198090Srdivacky CodeGenOpt::Default, 177198090Srdivacky bool GVsWithCode = true); 178193323Sed 179193323Sed /// addModuleProvider - Add a ModuleProvider to the list of modules that we 180193323Sed /// can JIT from. Note that this takes ownership of the ModuleProvider: when 181193323Sed /// the ExecutionEngine is destroyed, it destroys the MP as well. 182193323Sed virtual void addModuleProvider(ModuleProvider *P) { 183193323Sed Modules.push_back(P); 184193323Sed } 185193323Sed 186193323Sed //===----------------------------------------------------------------------===// 187193323Sed 188193323Sed const TargetData *getTargetData() const { return TD; } 189193323Sed 190193323Sed 191193323Sed /// removeModuleProvider - Remove a ModuleProvider from the list of modules. 192193323Sed /// Relases the Module from the ModuleProvider, materializing it in the 193193323Sed /// process, and returns the materialized Module. 194193323Sed virtual Module* removeModuleProvider(ModuleProvider *P, 195193323Sed std::string *ErrInfo = 0); 196193323Sed 197193323Sed /// deleteModuleProvider - Remove a ModuleProvider from the list of modules, 198193323Sed /// and deletes the ModuleProvider and owned Module. Avoids materializing 199193323Sed /// the underlying module. 200193323Sed virtual void deleteModuleProvider(ModuleProvider *P,std::string *ErrInfo = 0); 201193323Sed 202193323Sed /// FindFunctionNamed - Search all of the active modules to find the one that 203193323Sed /// defines FnName. This is very slow operation and shouldn't be used for 204193323Sed /// general code. 205193323Sed Function *FindFunctionNamed(const char *FnName); 206193323Sed 207193323Sed /// runFunction - Execute the specified function with the specified arguments, 208193323Sed /// and return the result. 209193323Sed /// 210193323Sed virtual GenericValue runFunction(Function *F, 211193323Sed const std::vector<GenericValue> &ArgValues) = 0; 212193323Sed 213193323Sed /// runStaticConstructorsDestructors - This method is used to execute all of 214193323Sed /// the static constructors or destructors for a program, depending on the 215193323Sed /// value of isDtors. 216193323Sed void runStaticConstructorsDestructors(bool isDtors); 217193323Sed /// runStaticConstructorsDestructors - This method is used to execute all of 218193323Sed /// the static constructors or destructors for a module, depending on the 219193323Sed /// value of isDtors. 220193323Sed void runStaticConstructorsDestructors(Module *module, bool isDtors); 221193323Sed 222193323Sed 223193323Sed /// runFunctionAsMain - This is a helper function which wraps runFunction to 224193323Sed /// handle the common task of starting up main with the specified argc, argv, 225193323Sed /// and envp parameters. 226193323Sed int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv, 227193323Sed const char * const * envp); 228193323Sed 229193323Sed 230193323Sed /// addGlobalMapping - Tell the execution engine that the specified global is 231193323Sed /// at the specified location. This is used internally as functions are JIT'd 232193323Sed /// and as global variables are laid out in memory. It can and should also be 233193323Sed /// used by clients of the EE that want to have an LLVM global overlay 234198090Srdivacky /// existing data in memory. Mappings are automatically removed when their 235198090Srdivacky /// GlobalValue is destroyed. 236193323Sed void addGlobalMapping(const GlobalValue *GV, void *Addr); 237193323Sed 238193323Sed /// clearAllGlobalMappings - Clear all global mappings and start over again 239193323Sed /// use in dynamic compilation scenarios when you want to move globals 240193323Sed void clearAllGlobalMappings(); 241193323Sed 242193323Sed /// clearGlobalMappingsFromModule - Clear all global mappings that came from a 243193323Sed /// particular module, because it has been removed from the JIT. 244193323Sed void clearGlobalMappingsFromModule(Module *M); 245193323Sed 246193323Sed /// updateGlobalMapping - Replace an existing mapping for GV with a new 247193323Sed /// address. This updates both maps as required. If "Addr" is null, the 248193323Sed /// entry for the global is removed from the mappings. This returns the old 249193323Sed /// value of the pointer, or null if it was not in the map. 250193323Sed void *updateGlobalMapping(const GlobalValue *GV, void *Addr); 251193323Sed 252193323Sed /// getPointerToGlobalIfAvailable - This returns the address of the specified 253193323Sed /// global value if it is has already been codegen'd, otherwise it returns 254193323Sed /// null. 255193323Sed /// 256193323Sed void *getPointerToGlobalIfAvailable(const GlobalValue *GV); 257193323Sed 258193323Sed /// getPointerToGlobal - This returns the address of the specified global 259198090Srdivacky /// value. This may involve code generation if it's a function. 260193323Sed /// 261193323Sed void *getPointerToGlobal(const GlobalValue *GV); 262193323Sed 263193323Sed /// getPointerToFunction - The different EE's represent function bodies in 264193323Sed /// different ways. They should each implement this to say what a function 265198090Srdivacky /// pointer should look like. When F is destroyed, the ExecutionEngine will 266198892Srdivacky /// remove its global mapping and free any machine code. Be sure no threads 267198892Srdivacky /// are running inside F when that happens. 268193323Sed /// 269193323Sed virtual void *getPointerToFunction(Function *F) = 0; 270193323Sed 271198892Srdivacky /// getPointerToBasicBlock - The different EE's represent basic blocks in 272198892Srdivacky /// different ways. Return the representation for a blockaddress of the 273198892Srdivacky /// specified block. 274198892Srdivacky /// 275198892Srdivacky virtual void *getPointerToBasicBlock(BasicBlock *BB) = 0; 276198892Srdivacky 277193323Sed /// getPointerToFunctionOrStub - If the specified function has been 278193323Sed /// code-gen'd, return a pointer to the function. If not, compile it, or use 279198090Srdivacky /// a stub to implement lazy compilation if available. See 280198090Srdivacky /// getPointerToFunction for the requirements on destroying F. 281193323Sed /// 282193323Sed virtual void *getPointerToFunctionOrStub(Function *F) { 283193323Sed // Default implementation, just codegen the function. 284193323Sed return getPointerToFunction(F); 285193323Sed } 286193323Sed 287193323Sed // The JIT overrides a version that actually does this. 288194178Sed virtual void runJITOnFunction(Function *, MachineCodeInfo * = 0) { } 289193323Sed 290193323Sed /// getGlobalValueAtAddress - Return the LLVM global value object that starts 291193323Sed /// at the specified address. 292193323Sed /// 293193323Sed const GlobalValue *getGlobalValueAtAddress(void *Addr); 294193323Sed 295193323Sed 296193323Sed void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, 297193323Sed const Type *Ty); 298193323Sed void InitializeMemory(const Constant *Init, void *Addr); 299193323Sed 300193323Sed /// recompileAndRelinkFunction - This method is used to force a function 301193323Sed /// which has already been compiled to be compiled again, possibly 302193323Sed /// after it has been modified. Then the entry to the old copy is overwritten 303193323Sed /// with a branch to the new copy. If there was no old copy, this acts 304193323Sed /// just like VM::getPointerToFunction(). 305193323Sed /// 306193323Sed virtual void *recompileAndRelinkFunction(Function *F) = 0; 307193323Sed 308193323Sed /// freeMachineCodeForFunction - Release memory in the ExecutionEngine 309193323Sed /// corresponding to the machine code emitted to execute this function, useful 310193323Sed /// for garbage-collecting generated code. 311193323Sed /// 312193323Sed virtual void freeMachineCodeForFunction(Function *F) = 0; 313193323Sed 314193323Sed /// getOrEmitGlobalVariable - Return the address of the specified global 315193323Sed /// variable, possibly emitting it to memory if needed. This is used by the 316198090Srdivacky /// Emitter. 317193323Sed virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) { 318193323Sed return getPointerToGlobal((GlobalValue*)GV); 319193323Sed } 320195098Sed 321195098Sed /// Registers a listener to be called back on various events within 322195098Sed /// the JIT. See JITEventListener.h for more details. Does not 323195098Sed /// take ownership of the argument. The argument may be NULL, in 324195098Sed /// which case these functions do nothing. 325198090Srdivacky virtual void RegisterJITEventListener(JITEventListener *) {} 326198090Srdivacky virtual void UnregisterJITEventListener(JITEventListener *) {} 327195098Sed 328198892Srdivacky /// DisableLazyCompilation - When lazy compilation is off (the default), the 329198892Srdivacky /// JIT will eagerly compile every function reachable from the argument to 330198892Srdivacky /// getPointerToFunction. If lazy compilation is turned on, the JIT will only 331198892Srdivacky /// compile the one function and emit stubs to compile the rest when they're 332198892Srdivacky /// first called. If lazy compilation is turned off again while some lazy 333198892Srdivacky /// stubs are still around, and one of those stubs is called, the program will 334198892Srdivacky /// abort. 335198892Srdivacky /// 336198892Srdivacky /// In order to safely compile lazily in a threaded program, the user must 337198892Srdivacky /// ensure that 1) only one thread at a time can call any particular lazy 338198892Srdivacky /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock 339198892Srdivacky /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a 340198892Srdivacky /// lazy stub. See http://llvm.org/PR5184 for details. 341193323Sed void DisableLazyCompilation(bool Disabled = true) { 342198892Srdivacky CompilingLazily = !Disabled; 343193323Sed } 344198892Srdivacky bool isCompilingLazily() const { 345198892Srdivacky return CompilingLazily; 346198892Srdivacky } 347198892Srdivacky // Deprecated in favor of isCompilingLazily (to reduce double-negatives). 348198892Srdivacky // Remove this in LLVM 2.8. 349193323Sed bool isLazyCompilationDisabled() const { 350198892Srdivacky return !CompilingLazily; 351193323Sed } 352193323Sed 353193323Sed /// DisableGVCompilation - If called, the JIT will abort if it's asked to 354193323Sed /// allocate space and populate a GlobalVariable that is not internal to 355193323Sed /// the module. 356193323Sed void DisableGVCompilation(bool Disabled = true) { 357193323Sed GVCompilationDisabled = Disabled; 358193323Sed } 359193323Sed bool isGVCompilationDisabled() const { 360193323Sed return GVCompilationDisabled; 361193323Sed } 362193323Sed 363193323Sed /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown 364193323Sed /// symbols with dlsym. A client can still use InstallLazyFunctionCreator to 365193323Sed /// resolve symbols in a custom way. 366193323Sed void DisableSymbolSearching(bool Disabled = true) { 367193323Sed SymbolSearchingDisabled = Disabled; 368193323Sed } 369193323Sed bool isSymbolSearchingDisabled() const { 370193323Sed return SymbolSearchingDisabled; 371193323Sed } 372193323Sed 373193323Sed /// EnableDlsymStubs - 374193323Sed void EnableDlsymStubs(bool Enabled = true) { 375193323Sed DlsymStubsEnabled = Enabled; 376193323Sed } 377193323Sed bool areDlsymStubsEnabled() const { 378193323Sed return DlsymStubsEnabled; 379193323Sed } 380193323Sed 381193323Sed /// InstallLazyFunctionCreator - If an unknown function is needed, the 382193323Sed /// specified function pointer is invoked to create it. If it returns null, 383193323Sed /// the JIT will abort. 384193323Sed void InstallLazyFunctionCreator(void* (*P)(const std::string &)) { 385193323Sed LazyFunctionCreator = P; 386193323Sed } 387193323Sed 388193323Sed /// InstallExceptionTableRegister - The JIT will use the given function 389193323Sed /// to register the exception tables it generates. 390193323Sed static void InstallExceptionTableRegister(void (*F)(void*)) { 391193323Sed ExceptionTableRegister = F; 392193323Sed } 393193323Sed 394193323Sed /// RegisterTable - Registers the given pointer as an exception table. It uses 395193323Sed /// the ExceptionTableRegister function. 396193323Sed static void RegisterTable(void* res) { 397193323Sed if (ExceptionTableRegister) 398193323Sed ExceptionTableRegister(res); 399193323Sed } 400193323Sed 401193323Sedprotected: 402193323Sed explicit ExecutionEngine(ModuleProvider *P); 403193323Sed 404193323Sed void emitGlobals(); 405193323Sed 406193323Sed // EmitGlobalVariable - This method emits the specified global variable to the 407193323Sed // address specified in GlobalAddresses, or allocates new memory if it's not 408193323Sed // already in the map. 409193323Sed void EmitGlobalVariable(const GlobalVariable *GV); 410193323Sed 411193323Sed GenericValue getConstantValue(const Constant *C); 412193323Sed void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, 413193323Sed const Type *Ty); 414193323Sed}; 415193323Sed 416198090Srdivackynamespace EngineKind { 417198090Srdivacky // These are actually bitmasks that get or-ed together. 418198090Srdivacky enum Kind { 419198090Srdivacky JIT = 0x1, 420198090Srdivacky Interpreter = 0x2 421198090Srdivacky }; 422198090Srdivacky const static Kind Either = (Kind)(JIT | Interpreter); 423198090Srdivacky} 424198090Srdivacky 425198090Srdivacky/// EngineBuilder - Builder class for ExecutionEngines. Use this by 426198090Srdivacky/// stack-allocating a builder, chaining the various set* methods, and 427198090Srdivacky/// terminating it with a .create() call. 428198090Srdivackyclass EngineBuilder { 429198090Srdivacky 430198090Srdivacky private: 431198090Srdivacky ModuleProvider *MP; 432198090Srdivacky EngineKind::Kind WhichEngine; 433198090Srdivacky std::string *ErrorStr; 434198090Srdivacky CodeGenOpt::Level OptLevel; 435198090Srdivacky JITMemoryManager *JMM; 436198090Srdivacky bool AllocateGVsWithCode; 437198090Srdivacky 438198090Srdivacky /// InitEngine - Does the common initialization of default options. 439198090Srdivacky /// 440198090Srdivacky void InitEngine() { 441198090Srdivacky WhichEngine = EngineKind::Either; 442198090Srdivacky ErrorStr = NULL; 443198090Srdivacky OptLevel = CodeGenOpt::Default; 444198090Srdivacky JMM = NULL; 445198090Srdivacky AllocateGVsWithCode = false; 446198090Srdivacky } 447198090Srdivacky 448198090Srdivacky public: 449198090Srdivacky /// EngineBuilder - Constructor for EngineBuilder. If create() is called and 450198090Srdivacky /// is successful, the created engine takes ownership of the module 451198090Srdivacky /// provider. 452198090Srdivacky EngineBuilder(ModuleProvider *mp) : MP(mp) { 453198090Srdivacky InitEngine(); 454198090Srdivacky } 455198090Srdivacky 456198090Srdivacky /// EngineBuilder - Overloaded constructor that automatically creates an 457198090Srdivacky /// ExistingModuleProvider for an existing module. 458198090Srdivacky EngineBuilder(Module *m); 459198090Srdivacky 460198090Srdivacky /// setEngineKind - Controls whether the user wants the interpreter, the JIT, 461198090Srdivacky /// or whichever engine works. This option defaults to EngineKind::Either. 462198090Srdivacky EngineBuilder &setEngineKind(EngineKind::Kind w) { 463198090Srdivacky WhichEngine = w; 464198090Srdivacky return *this; 465198090Srdivacky } 466198090Srdivacky 467198090Srdivacky /// setJITMemoryManager - Sets the memory manager to use. This allows 468198090Srdivacky /// clients to customize their memory allocation policies. If create() is 469198090Srdivacky /// called and is successful, the created engine takes ownership of the 470198090Srdivacky /// memory manager. This option defaults to NULL. 471198090Srdivacky EngineBuilder &setJITMemoryManager(JITMemoryManager *jmm) { 472198090Srdivacky JMM = jmm; 473198090Srdivacky return *this; 474198090Srdivacky } 475198090Srdivacky 476198090Srdivacky /// setErrorStr - Set the error string to write to on error. This option 477198090Srdivacky /// defaults to NULL. 478198090Srdivacky EngineBuilder &setErrorStr(std::string *e) { 479198090Srdivacky ErrorStr = e; 480198090Srdivacky return *this; 481198090Srdivacky } 482198090Srdivacky 483198090Srdivacky /// setOptLevel - Set the optimization level for the JIT. This option 484198090Srdivacky /// defaults to CodeGenOpt::Default. 485198090Srdivacky EngineBuilder &setOptLevel(CodeGenOpt::Level l) { 486198090Srdivacky OptLevel = l; 487198090Srdivacky return *this; 488198090Srdivacky } 489198090Srdivacky 490198090Srdivacky /// setAllocateGVsWithCode - Sets whether global values should be allocated 491198090Srdivacky /// into the same buffer as code. For most applications this should be set 492198090Srdivacky /// to false. Allocating globals with code breaks freeMachineCodeForFunction 493198090Srdivacky /// and is probably unsafe and bad for performance. However, we have clients 494198090Srdivacky /// who depend on this behavior, so we must support it. This option defaults 495198090Srdivacky /// to false so that users of the new API can safely use the new memory 496198090Srdivacky /// manager and free machine code. 497198090Srdivacky EngineBuilder &setAllocateGVsWithCode(bool a) { 498198090Srdivacky AllocateGVsWithCode = a; 499198090Srdivacky return *this; 500198090Srdivacky } 501198090Srdivacky 502198090Srdivacky ExecutionEngine *create(); 503198090Srdivacky}; 504198090Srdivacky 505193323Sed} // End llvm namespace 506193323Sed 507193323Sed#endif 508