ExecutionEngine.h revision 218893
12061Sjkh//===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===// 250479Speter// 32061Sjkh// The LLVM Compiler Infrastructure 438666Sjb// 532427Sjb// This file is distributed under the University of Illinois Open Source 6111131Sru// License. See LICENSE.TXT for details. 7111131Sru// 838666Sjb//===----------------------------------------------------------------------===// 938666Sjb// 1038666Sjb// This file defines the abstract interface that implements execution support 1138666Sjb// for LLVM. 1264049Salex// 1364049Salex//===----------------------------------------------------------------------===// 14116679Ssimokawa 1566071Smarkm#ifndef LLVM_EXECUTION_ENGINE_H 16116679Ssimokawa#define LLVM_EXECUTION_ENGINE_H 1773504Sobrien 1838666Sjb#include <vector> 1932427Sjb#include <map> 2038666Sjb#include <string> 21108451Sschweikh#include "llvm/ADT/SmallVector.h" 2238666Sjb#include "llvm/ADT/StringRef.h" 2338666Sjb#include "llvm/ADT/ValueMap.h" 2438666Sjb#include "llvm/Support/ValueHandle.h" 2538666Sjb#include "llvm/Support/Mutex.h" 2617308Speter#include "llvm/Target/TargetMachine.h" 2791606Skeramida 2819175Sbdenamespace llvm { 2996205Sjwd 3096205Sjwdstruct GenericValue; 3138042Sbdeclass Constant; 3296205Sjwdclass ExecutionEngine; 3396205Sjwdclass Function; 3438042Sbdeclass GlobalVariable; 3596205Sjwdclass GlobalValue; 3696205Sjwdclass JITEventListener; 3717308Speterclass JITMemoryManager; 3896205Sjwdclass MachineCodeInfo; 3996205Sjwdclass Module; 4017308Speterclass MutexGuard; 4196205Sjwdclass TargetData; 4296205Sjwdclass Type; 4396205Sjwd 4496205Sjwd/// \brief Helper class for helping synchronize access to the global address map 4596205Sjwd/// table. 4696205Sjwdclass ExecutionEngineState { 4796205Sjwdpublic: 4896205Sjwd struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> { 4996205Sjwd typedef ExecutionEngineState *ExtraData; 5096205Sjwd static sys::Mutex *getMutex(ExecutionEngineState *EES); 5196205Sjwd static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old); 5296205Sjwd static void onRAUW(ExecutionEngineState *, const GlobalValue *, 5398775Sdillon const GlobalValue *); 5498723Sdillon }; 5598723Sdillon 5698723Sdillon typedef ValueMap<const GlobalValue *, void *, AddressMapConfig> 5798723Sdillon GlobalAddressMapTy; 5838666Sjb 5938666Sjbprivate: 6017308Speter ExecutionEngine &EE; 61123311Speter 62123311Speter /// GlobalAddressMap - A mapping between LLVM global values and their 63123311Speter /// actualized version... 64123311Speter GlobalAddressMapTy GlobalAddressMap; 65142585Sru 66142644Sru /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap, 67142644Sru /// used to convert raw addresses into the LLVM global value that is emitted 68116679Ssimokawa /// at the address. This map is not computed unless getGlobalValueAtAddress 69120760Sru /// is called at some point. 70128189Sdes std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap; 71127360Sru 72123311Speterpublic: 73137288Speter ExecutionEngineState(ExecutionEngine &EE); 74137288Speter 752061Sjkh GlobalAddressMapTy &getGlobalAddressMap(const MutexGuard &) { 7697769Sru return GlobalAddressMap; 7797252Sru } 78119579Sru 7997252Sru std::map<void*, AssertingVH<const GlobalValue> > & 8095730Sru getGlobalAddressReverseMap(const MutexGuard &) { 8195793Sru return GlobalAddressReverseMap; 82111617Sru } 8395730Sru 84116679Ssimokawa /// \brief Erase an entry from the mapping table. 8595730Sru /// 86116679Ssimokawa /// \returns The address that \arg ToUnmap was happed to. 8795730Sru void *RemoveMapping(const MutexGuard &, const GlobalValue *ToUnmap); 88110035Sru}; 89107516Sru 90138921Sru/// \brief Abstract interface for implementation execution of LLVM modules, 91138921Sru/// designed to support both interpreter and just-in-time (JIT) compiler 92138921Sru/// implementations. 93133942Sruclass ExecutionEngine { 94133942Sru /// The state object holding the global address mapping, which must be 95133942Sru /// accessed synchronously. 96133942Sru // 97110035Sru // FIXME: There is no particular need the entire map needs to be 98117234Sru // synchronized. Wouldn't a reader-writer design be better here? 99110035Sru ExecutionEngineState EEState; 100117229Sru 101117234Sru /// The target data for the platform for which execution is being performed. 10254324Smarcel const TargetData *TD; 10317308Speter 104119519Smarcel /// Whether lazy JIT compilation is enabled. 105119519Smarcel bool CompilingLazily; 106119519Smarcel 107119519Smarcel /// Whether JIT compilation of external global variables is allowed. 108119519Smarcel bool GVCompilationDisabled; 109119519Smarcel 110119579Sru /// Whether the JIT should perform lookups of external symbols (e.g., 111119519Smarcel /// using dlsym). 112119519Smarcel bool SymbolSearchingDisabled; 113119519Smarcel 114119519Smarcel friend class EngineBuilder; // To allow access to JITCtor and InterpCtor. 115119519Smarcel 116126031Sgadprotected: 117126024Sgad /// The list of Modules that we are JIT'ing from. We use a SmallVector to 118126024Sgad /// optimize for the case where there is only one module. 119126024Sgad SmallVector<Module*, 1> Modules; 120126024Sgad 121126024Sgad void setTargetData(const TargetData *td) { 122126024Sgad TD = td; 123126024Sgad } 124126024Sgad 125126024Sgad /// getMemoryforGV - Allocate memory for a global variable. 126126024Sgad virtual char *getMemoryForGV(const GlobalVariable *GV); 127126024Sgad 128126024Sgad // To avoid having libexecutionengine depend on the JIT and interpreter 129126024Sgad // libraries, the execution engine implementations set these functions to ctor 130126031Sgad // pointers at startup time if they are linked in. 131126024Sgad static ExecutionEngine *(*JITCtor)( 132126024Sgad Module *M, 133126024Sgad std::string *ErrorStr, 134126024Sgad JITMemoryManager *JMM, 135126024Sgad CodeGenOpt::Level OptLevel, 136126024Sgad bool GVsWithCode, 137126024Sgad CodeModel::Model CMM, 138133376Sharti StringRef MArch, 139126024Sgad StringRef MCPU, 140126024Sgad const SmallVectorImpl<std::string>& MAttrs); 141126024Sgad static ExecutionEngine *(*MCJITCtor)( 142126024Sgad Module *M, 143126024Sgad std::string *ErrorStr, 144125885Sgad JITMemoryManager *JMM, 145125885Sgad CodeGenOpt::Level OptLevel, 14638666Sjb bool GVsWithCode, 14717308Speter CodeModel::Model CMM, 148119519Smarcel StringRef MArch, 149119579Sru StringRef MCPU, 150133376Sharti const SmallVectorImpl<std::string>& MAttrs); 151110035Sru static ExecutionEngine *(*InterpCtor)(Module *M, 1522302Spaul std::string *ErrorStr); 15339206Sjkh 15439206Sjkh /// LazyFunctionCreator - If an unknown function is needed, this function 15539206Sjkh /// pointer is invoked to create it. If this returns null, the JIT will 156133945Sru /// abort. 157133945Sru void *(*LazyFunctionCreator)(const std::string &); 158132358Smarkm 15917308Speter /// ExceptionTableRegister - If Exception Handling is set, the JIT will 16054324Smarcel /// register dwarf tables with this function. 16154324Smarcel typedef void (*EERegisterFn)(void*); 162132234Smarcel EERegisterFn ExceptionTableRegister; 163132234Smarcel EERegisterFn ExceptionTableDeregister; 164132234Smarcel std::vector<void*> AllExceptionTables; 165132234Smarcel 16654324Smarcelpublic: 16754324Smarcel /// lock - This lock protects the ExecutionEngine, JIT, JITResolver and 16854324Smarcel /// JITEmitter classes. It must be held while changing the internal state of 169118531Sru /// any of those classes. 17054324Smarcel sys::Mutex lock; 17154324Smarcel 17254324Smarcel //===--------------------------------------------------------------------===// 17354324Smarcel // ExecutionEngine Startup 17454324Smarcel //===--------------------------------------------------------------------===// 17554324Smarcel 176133376Sharti virtual ~ExecutionEngine(); 17754324Smarcel 178133376Sharti /// create - This is the factory method for creating an execution engine which 179133376Sharti /// is appropriate for the current machine. This takes ownership of the 18054324Smarcel /// module. 18154324Smarcel /// 18254324Smarcel /// \param GVsWithCode - Allocating globals with code breaks 18354324Smarcel /// freeMachineCodeForFunction and is probably unsafe and bad for performance. 18454324Smarcel /// However, we have clients who depend on this behavior, so we must support 185133376Sharti /// it. Eventually, when we're willing to break some backwards compatability, 18654324Smarcel /// this flag should be flipped to false, so that by default 18754324Smarcel /// freeMachineCodeForFunction works. 18854324Smarcel static ExecutionEngine *create(Module *M, 189118531Sru bool ForceInterpreter = false, 190118531Sru std::string *ErrorStr = 0, 19154324Smarcel CodeGenOpt::Level OptLevel = 192132234Smarcel CodeGenOpt::Default, 193132234Smarcel bool GVsWithCode = true); 194132234Smarcel 195132234Smarcel /// createJIT - This is the factory method for creating a JIT for the current 196132234Smarcel /// machine, it does not fall back to the interpreter. This takes ownership 197132588Skensmith /// of the Module and JITMemoryManager if successful. 198132358Smarkm /// 199132234Smarcel /// Clients should make sure to initialize targets prior to calling this 200132358Smarkm /// function. 201132358Smarkm static ExecutionEngine *createJIT(Module *M, 202132358Smarkm std::string *ErrorStr = 0, 203132358Smarkm JITMemoryManager *JMM = 0, 204132234Smarcel CodeGenOpt::Level OptLevel = 205132234Smarcel CodeGenOpt::Default, 206132234Smarcel bool GVsWithCode = true, 20754324Smarcel CodeModel::Model CMM = 20854324Smarcel CodeModel::Default); 20995730Sru 21095730Sru /// addModule - Add a Module to the list of modules that we can JIT from. 21195730Sru /// Note that this takes ownership of the Module: when the ExecutionEngine is 21295730Sru /// destroyed, it destroys the Module as well. 21395730Sru virtual void addModule(Module *M) { 21495730Sru Modules.push_back(M); 21595730Sru } 21638666Sjb 217107374Sru //===--------------------------------------------------------------------===// 21817308Speter 21955678Smarcel const TargetData *getTargetData() const { return TD; } 220143032Sharti 221138515Sharti /// removeModule - Remove a Module from the list of modules. Returns true if 222117793Sru /// M is found. 223110035Sru virtual bool removeModule(Module *M); 224110035Sru 225110035Sru /// FindFunctionNamed - Search all of the active modules to find the one that 2262061Sjkh /// defines FnName. This is very slow operation and shouldn't be used for 22717308Speter /// general code. 228107516Sru Function *FindFunctionNamed(const char *FnName); 229107374Sru 23055678Smarcel /// runFunction - Execute the specified function with the specified arguments, 231107516Sru /// and return the result. 232107516Sru virtual GenericValue runFunction(Function *F, 233107516Sru const std::vector<GenericValue> &ArgValues) = 0; 234107516Sru 235107516Sru /// runStaticConstructorsDestructors - This method is used to execute all of 236139112Sru /// the static constructors or destructors for a program. 237107516Sru /// 238107516Sru /// \param isDtors - Run the destructors instead of constructors. 239122204Skris void runStaticConstructorsDestructors(bool isDtors); 24055678Smarcel 24155678Smarcel /// runStaticConstructorsDestructors - This method is used to execute all of 242116696Sru /// the static constructors or destructors for a particular module. 24355678Smarcel /// 244133376Sharti /// \param isDtors - Run the destructors instead of constructors. 245107516Sru void runStaticConstructorsDestructors(Module *module, bool isDtors); 246107516Sru 247107516Sru 248107516Sru /// runFunctionAsMain - This is a helper function which wraps runFunction to 24955678Smarcel /// handle the common task of starting up main with the specified argc, argv, 25055678Smarcel /// and envp parameters. 251111131Sru int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv, 252111131Sru const char * const * envp); 253111131Sru 254133945Sru 255111131Sru /// addGlobalMapping - Tell the execution engine that the specified global is 256111131Sru /// at the specified location. This is used internally as functions are JIT'd 257133945Sru /// and as global variables are laid out in memory. It can and should also be 258133945Sru /// used by clients of the EE that want to have an LLVM global overlay 259103985Sphk /// existing data in memory. Mappings are automatically removed when their 260103985Sphk /// GlobalValue is destroyed. 261103985Sphk void addGlobalMapping(const GlobalValue *GV, void *Addr); 262133945Sru 263133945Sru /// clearAllGlobalMappings - Clear all global mappings and start over again, 264133945Sru /// for use in dynamic compilation scenarios to move globals. 265133945Sru void clearAllGlobalMappings(); 266133945Sru 267133945Sru /// clearGlobalMappingsFromModule - Clear all global mappings that came from a 268111131Sru /// particular module, because it has been removed from the JIT. 269131876Sphk void clearGlobalMappingsFromModule(Module *M); 270111131Sru 271111131Sru /// updateGlobalMapping - Replace an existing mapping for GV with a new 272111131Sru /// address. This updates both maps as required. If "Addr" is null, the 273111131Sru /// entry for the global is removed from the mappings. This returns the old 274111131Sru /// value of the pointer, or null if it was not in the map. 275111131Sru void *updateGlobalMapping(const GlobalValue *GV, void *Addr); 276111133Sru 277103985Sphk /// getPointerToGlobalIfAvailable - This returns the address of the specified 278133945Sru /// global value if it is has already been codegen'd, otherwise it returns 279111131Sru /// null. 280103985Sphk void *getPointerToGlobalIfAvailable(const GlobalValue *GV); 281111131Sru 282133945Sru /// getPointerToGlobal - This returns the address of the specified global 283133945Sru /// value. This may involve code generation if it's a function. 284133945Sru void *getPointerToGlobal(const GlobalValue *GV); 285103985Sphk 286118531Sru /// getPointerToFunction - The different EE's represent function bodies in 287118531Sru /// different ways. They should each implement this to say what a function 288103985Sphk /// pointer should look like. When F is destroyed, the ExecutionEngine will 289103985Sphk /// remove its global mapping and free any machine code. Be sure no threads 290126485Sru /// are running inside F when that happens. 291111131Sru virtual void *getPointerToFunction(Function *F) = 0; 292111131Sru 293103985Sphk /// getPointerToBasicBlock - The different EE's represent basic blocks in 294111131Sru /// different ways. Return the representation for a blockaddress of the 295131876Sphk /// specified block. 296111131Sru virtual void *getPointerToBasicBlock(BasicBlock *BB) = 0; 297111131Sru 298111131Sru /// getPointerToFunctionOrStub - If the specified function has been 299103985Sphk /// code-gen'd, return a pointer to the function. If not, compile it, or use 300133945Sru /// a stub to implement lazy compilation if available. See 301 /// getPointerToFunction for the requirements on destroying F. 302 virtual void *getPointerToFunctionOrStub(Function *F) { 303 // Default implementation, just codegen the function. 304 return getPointerToFunction(F); 305 } 306 307 // The JIT overrides a version that actually does this. 308 virtual void runJITOnFunction(Function *, MachineCodeInfo * = 0) { } 309 310 /// getGlobalValueAtAddress - Return the LLVM global value object that starts 311 /// at the specified address. 312 /// 313 const GlobalValue *getGlobalValueAtAddress(void *Addr); 314 315 /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr. 316 /// Ptr is the address of the memory at which to store Val, cast to 317 /// GenericValue *. It is not a pointer to a GenericValue containing the 318 /// address at which to store Val. 319 void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, 320 const Type *Ty); 321 322 void InitializeMemory(const Constant *Init, void *Addr); 323 324 /// recompileAndRelinkFunction - This method is used to force a function which 325 /// has already been compiled to be compiled again, possibly after it has been 326 /// modified. Then the entry to the old copy is overwritten with a branch to 327 /// the new copy. If there was no old copy, this acts just like 328 /// VM::getPointerToFunction(). 329 virtual void *recompileAndRelinkFunction(Function *F) = 0; 330 331 /// freeMachineCodeForFunction - Release memory in the ExecutionEngine 332 /// corresponding to the machine code emitted to execute this function, useful 333 /// for garbage-collecting generated code. 334 virtual void freeMachineCodeForFunction(Function *F) = 0; 335 336 /// getOrEmitGlobalVariable - Return the address of the specified global 337 /// variable, possibly emitting it to memory if needed. This is used by the 338 /// Emitter. 339 virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) { 340 return getPointerToGlobal((GlobalValue*)GV); 341 } 342 343 /// Registers a listener to be called back on various events within 344 /// the JIT. See JITEventListener.h for more details. Does not 345 /// take ownership of the argument. The argument may be NULL, in 346 /// which case these functions do nothing. 347 virtual void RegisterJITEventListener(JITEventListener *) {} 348 virtual void UnregisterJITEventListener(JITEventListener *) {} 349 350 /// DisableLazyCompilation - When lazy compilation is off (the default), the 351 /// JIT will eagerly compile every function reachable from the argument to 352 /// getPointerToFunction. If lazy compilation is turned on, the JIT will only 353 /// compile the one function and emit stubs to compile the rest when they're 354 /// first called. If lazy compilation is turned off again while some lazy 355 /// stubs are still around, and one of those stubs is called, the program will 356 /// abort. 357 /// 358 /// In order to safely compile lazily in a threaded program, the user must 359 /// ensure that 1) only one thread at a time can call any particular lazy 360 /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock 361 /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a 362 /// lazy stub. See http://llvm.org/PR5184 for details. 363 void DisableLazyCompilation(bool Disabled = true) { 364 CompilingLazily = !Disabled; 365 } 366 bool isCompilingLazily() const { 367 return CompilingLazily; 368 } 369 // Deprecated in favor of isCompilingLazily (to reduce double-negatives). 370 // Remove this in LLVM 2.8. 371 bool isLazyCompilationDisabled() const { 372 return !CompilingLazily; 373 } 374 375 /// DisableGVCompilation - If called, the JIT will abort if it's asked to 376 /// allocate space and populate a GlobalVariable that is not internal to 377 /// the module. 378 void DisableGVCompilation(bool Disabled = true) { 379 GVCompilationDisabled = Disabled; 380 } 381 bool isGVCompilationDisabled() const { 382 return GVCompilationDisabled; 383 } 384 385 /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown 386 /// symbols with dlsym. A client can still use InstallLazyFunctionCreator to 387 /// resolve symbols in a custom way. 388 void DisableSymbolSearching(bool Disabled = true) { 389 SymbolSearchingDisabled = Disabled; 390 } 391 bool isSymbolSearchingDisabled() const { 392 return SymbolSearchingDisabled; 393 } 394 395 /// InstallLazyFunctionCreator - If an unknown function is needed, the 396 /// specified function pointer is invoked to create it. If it returns null, 397 /// the JIT will abort. 398 void InstallLazyFunctionCreator(void* (*P)(const std::string &)) { 399 LazyFunctionCreator = P; 400 } 401 402 /// InstallExceptionTableRegister - The JIT will use the given function 403 /// to register the exception tables it generates. 404 void InstallExceptionTableRegister(EERegisterFn F) { 405 ExceptionTableRegister = F; 406 } 407 void InstallExceptionTableDeregister(EERegisterFn F) { 408 ExceptionTableDeregister = F; 409 } 410 411 /// RegisterTable - Registers the given pointer as an exception table. It 412 /// uses the ExceptionTableRegister function. 413 void RegisterTable(void* res) { 414 if (ExceptionTableRegister) { 415 ExceptionTableRegister(res); 416 AllExceptionTables.push_back(res); 417 } 418 } 419 420 /// DeregisterAllTables - Deregisters all previously registered pointers to an 421 /// exception tables. It uses the ExceptionTableoDeregister function. 422 void DeregisterAllTables(); 423 424protected: 425 explicit ExecutionEngine(Module *M); 426 427 void emitGlobals(); 428 429 void EmitGlobalVariable(const GlobalVariable *GV); 430 431 GenericValue getConstantValue(const Constant *C); 432 void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, 433 const Type *Ty); 434}; 435 436namespace EngineKind { 437 // These are actually bitmasks that get or-ed together. 438 enum Kind { 439 JIT = 0x1, 440 Interpreter = 0x2 441 }; 442 const static Kind Either = (Kind)(JIT | Interpreter); 443} 444 445/// EngineBuilder - Builder class for ExecutionEngines. Use this by 446/// stack-allocating a builder, chaining the various set* methods, and 447/// terminating it with a .create() call. 448class EngineBuilder { 449private: 450 Module *M; 451 EngineKind::Kind WhichEngine; 452 std::string *ErrorStr; 453 CodeGenOpt::Level OptLevel; 454 JITMemoryManager *JMM; 455 bool AllocateGVsWithCode; 456 CodeModel::Model CMModel; 457 std::string MArch; 458 std::string MCPU; 459 SmallVector<std::string, 4> MAttrs; 460 bool UseMCJIT; 461 462 /// InitEngine - Does the common initialization of default options. 463 void InitEngine() { 464 WhichEngine = EngineKind::Either; 465 ErrorStr = NULL; 466 OptLevel = CodeGenOpt::Default; 467 JMM = NULL; 468 AllocateGVsWithCode = false; 469 CMModel = CodeModel::Default; 470 UseMCJIT = false; 471 } 472 473public: 474 /// EngineBuilder - Constructor for EngineBuilder. If create() is called and 475 /// is successful, the created engine takes ownership of the module. 476 EngineBuilder(Module *m) : M(m) { 477 InitEngine(); 478 } 479 480 /// setEngineKind - Controls whether the user wants the interpreter, the JIT, 481 /// or whichever engine works. This option defaults to EngineKind::Either. 482 EngineBuilder &setEngineKind(EngineKind::Kind w) { 483 WhichEngine = w; 484 return *this; 485 } 486 487 /// setJITMemoryManager - Sets the memory manager to use. This allows 488 /// clients to customize their memory allocation policies. If create() is 489 /// called and is successful, the created engine takes ownership of the 490 /// memory manager. This option defaults to NULL. 491 EngineBuilder &setJITMemoryManager(JITMemoryManager *jmm) { 492 JMM = jmm; 493 return *this; 494 } 495 496 /// setErrorStr - Set the error string to write to on error. This option 497 /// defaults to NULL. 498 EngineBuilder &setErrorStr(std::string *e) { 499 ErrorStr = e; 500 return *this; 501 } 502 503 /// setOptLevel - Set the optimization level for the JIT. This option 504 /// defaults to CodeGenOpt::Default. 505 EngineBuilder &setOptLevel(CodeGenOpt::Level l) { 506 OptLevel = l; 507 return *this; 508 } 509 510 /// setCodeModel - Set the CodeModel that the ExecutionEngine target 511 /// data is using. Defaults to target specific default "CodeModel::Default". 512 EngineBuilder &setCodeModel(CodeModel::Model M) { 513 CMModel = M; 514 return *this; 515 } 516 517 /// setAllocateGVsWithCode - Sets whether global values should be allocated 518 /// into the same buffer as code. For most applications this should be set 519 /// to false. Allocating globals with code breaks freeMachineCodeForFunction 520 /// and is probably unsafe and bad for performance. However, we have clients 521 /// who depend on this behavior, so we must support it. This option defaults 522 /// to false so that users of the new API can safely use the new memory 523 /// manager and free machine code. 524 EngineBuilder &setAllocateGVsWithCode(bool a) { 525 AllocateGVsWithCode = a; 526 return *this; 527 } 528 529 /// setMArch - Override the architecture set by the Module's triple. 530 EngineBuilder &setMArch(StringRef march) { 531 MArch.assign(march.begin(), march.end()); 532 return *this; 533 } 534 535 /// setMCPU - Target a specific cpu type. 536 EngineBuilder &setMCPU(StringRef mcpu) { 537 MCPU.assign(mcpu.begin(), mcpu.end()); 538 return *this; 539 } 540 541 /// setUseMCJIT - Set whether the MC-JIT implementation should be used 542 /// (experimental). 543 void setUseMCJIT(bool Value) { 544 UseMCJIT = Value; 545 } 546 547 /// setMAttrs - Set cpu-specific attributes. 548 template<typename StringSequence> 549 EngineBuilder &setMAttrs(const StringSequence &mattrs) { 550 MAttrs.clear(); 551 MAttrs.append(mattrs.begin(), mattrs.end()); 552 return *this; 553 } 554 555 ExecutionEngine *create(); 556}; 557 558} // End llvm namespace 559 560#endif 561