LLVM API Documentation

ExecutionEngine/ExecutionEngine.h
Go to the documentation of this file.
00001 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the abstract interface that implements execution support
00011 // for LLVM.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
00016 #define LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
00017 
00018 #include "llvm-c/ExecutionEngine.h"
00019 #include "llvm/ADT/SmallVector.h"
00020 #include "llvm/ADT/StringRef.h"
00021 #include "llvm/IR/Module.h"
00022 #include "llvm/IR/ValueHandle.h"
00023 #include "llvm/IR/ValueMap.h"
00024 #include "llvm/MC/MCCodeGenInfo.h"
00025 #include "llvm/Object/Binary.h"
00026 #include "llvm/Support/ErrorHandling.h"
00027 #include "llvm/Support/Mutex.h"
00028 #include "llvm/Target/TargetMachine.h"
00029 #include "llvm/Target/TargetOptions.h"
00030 #include <map>
00031 #include <string>
00032 #include <vector>
00033 
00034 namespace llvm {
00035 
00036 struct GenericValue;
00037 class Constant;
00038 class DataLayout;
00039 class ExecutionEngine;
00040 class Function;
00041 class GlobalVariable;
00042 class GlobalValue;
00043 class JITEventListener;
00044 class JITMemoryManager;
00045 class MachineCodeInfo;
00046 class MutexGuard;
00047 class ObjectCache;
00048 class RTDyldMemoryManager;
00049 class Triple;
00050 class Type;
00051 
00052 namespace object {
00053   class Archive;
00054   class ObjectFile;
00055 }
00056 
00057 /// \brief Helper class for helping synchronize access to the global address map
00058 /// table.  Access to this class should be serialized under a mutex.
00059 class ExecutionEngineState {
00060 public:
00061   struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
00062     typedef ExecutionEngineState *ExtraData;
00063     static sys::Mutex *getMutex(ExecutionEngineState *EES);
00064     static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
00065     static void onRAUW(ExecutionEngineState *, const GlobalValue *,
00066                        const GlobalValue *);
00067   };
00068 
00069   typedef ValueMap<const GlobalValue *, void *, AddressMapConfig>
00070       GlobalAddressMapTy;
00071 
00072 private:
00073   ExecutionEngine &EE;
00074 
00075   /// GlobalAddressMap - A mapping between LLVM global values and their
00076   /// actualized version...
00077   GlobalAddressMapTy GlobalAddressMap;
00078 
00079   /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap,
00080   /// used to convert raw addresses into the LLVM global value that is emitted
00081   /// at the address.  This map is not computed unless getGlobalValueAtAddress
00082   /// is called at some point.
00083   std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap;
00084 
00085 public:
00086   ExecutionEngineState(ExecutionEngine &EE);
00087 
00088   GlobalAddressMapTy &getGlobalAddressMap() {
00089     return GlobalAddressMap;
00090   }
00091 
00092   std::map<void*, AssertingVH<const GlobalValue> > &
00093   getGlobalAddressReverseMap() {
00094     return GlobalAddressReverseMap;
00095   }
00096 
00097   /// \brief Erase an entry from the mapping table.
00098   ///
00099   /// \returns The address that \p ToUnmap was happed to.
00100   void *RemoveMapping(const GlobalValue *ToUnmap);
00101 };
00102 
00103 /// \brief Abstract interface for implementation execution of LLVM modules,
00104 /// designed to support both interpreter and just-in-time (JIT) compiler
00105 /// implementations.
00106 class ExecutionEngine {
00107   /// The state object holding the global address mapping, which must be
00108   /// accessed synchronously.
00109   //
00110   // FIXME: There is no particular need the entire map needs to be
00111   // synchronized.  Wouldn't a reader-writer design be better here?
00112   ExecutionEngineState EEState;
00113 
00114   /// The target data for the platform for which execution is being performed.
00115   const DataLayout *DL;
00116 
00117   /// Whether lazy JIT compilation is enabled.
00118   bool CompilingLazily;
00119 
00120   /// Whether JIT compilation of external global variables is allowed.
00121   bool GVCompilationDisabled;
00122 
00123   /// Whether the JIT should perform lookups of external symbols (e.g.,
00124   /// using dlsym).
00125   bool SymbolSearchingDisabled;
00126 
00127   /// Whether the JIT should verify IR modules during compilation.
00128   bool VerifyModules;
00129 
00130   friend class EngineBuilder;  // To allow access to JITCtor and InterpCtor.
00131 
00132 protected:
00133   /// The list of Modules that we are JIT'ing from.  We use a SmallVector to
00134   /// optimize for the case where there is only one module.
00135   SmallVector<std::unique_ptr<Module>, 1> Modules;
00136 
00137   void setDataLayout(const DataLayout *Val) { DL = Val; }
00138 
00139   /// getMemoryforGV - Allocate memory for a global variable.
00140   virtual char *getMemoryForGV(const GlobalVariable *GV);
00141 
00142   static ExecutionEngine *(*MCJITCtor)(std::unique_ptr<Module> M,
00143                                        std::string *ErrorStr,
00144                                        RTDyldMemoryManager *MCJMM,
00145                                        std::unique_ptr<TargetMachine> TM);
00146   static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M,
00147                                         std::string *ErrorStr);
00148 
00149   /// LazyFunctionCreator - If an unknown function is needed, this function
00150   /// pointer is invoked to create it.  If this returns null, the JIT will
00151   /// abort.
00152   void *(*LazyFunctionCreator)(const std::string &);
00153 
00154 public:
00155   /// lock - This lock protects the ExecutionEngine and MCJIT classes. It must
00156   /// be held while changing the internal state of any of those classes.
00157   sys::Mutex lock;
00158 
00159   //===--------------------------------------------------------------------===//
00160   //  ExecutionEngine Startup
00161   //===--------------------------------------------------------------------===//
00162 
00163   virtual ~ExecutionEngine();
00164 
00165   /// Add a Module to the list of modules that we can JIT from.
00166   virtual void addModule(std::unique_ptr<Module> M) {
00167     Modules.push_back(std::move(M));
00168   }
00169 
00170   /// addObjectFile - Add an ObjectFile to the execution engine.
00171   ///
00172   /// This method is only supported by MCJIT.  MCJIT will immediately load the
00173   /// object into memory and adds its symbols to the list used to resolve
00174   /// external symbols while preparing other objects for execution.
00175   ///
00176   /// Objects added using this function will not be made executable until
00177   /// needed by another object.
00178   ///
00179   /// MCJIT will take ownership of the ObjectFile.
00180   virtual void addObjectFile(std::unique_ptr<object::ObjectFile> O);
00181   virtual void addObjectFile(object::OwningBinary<object::ObjectFile> O);
00182 
00183   /// addArchive - Add an Archive to the execution engine.
00184   ///
00185   /// This method is only supported by MCJIT.  MCJIT will use the archive to
00186   /// resolve external symbols in objects it is loading.  If a symbol is found
00187   /// in the Archive the contained object file will be extracted (in memory)
00188   /// and loaded for possible execution.
00189   virtual void addArchive(object::OwningBinary<object::Archive> A);
00190 
00191   //===--------------------------------------------------------------------===//
00192 
00193   const DataLayout *getDataLayout() const { return DL; }
00194 
00195   /// removeModule - Remove a Module from the list of modules.  Returns true if
00196   /// M is found.
00197   virtual bool removeModule(Module *M);
00198 
00199   /// FindFunctionNamed - Search all of the active modules to find the one that
00200   /// defines FnName.  This is very slow operation and shouldn't be used for
00201   /// general code.
00202   virtual Function *FindFunctionNamed(const char *FnName);
00203 
00204   /// runFunction - Execute the specified function with the specified arguments,
00205   /// and return the result.
00206   virtual GenericValue runFunction(Function *F,
00207                                 const std::vector<GenericValue> &ArgValues) = 0;
00208 
00209   /// getPointerToNamedFunction - This method returns the address of the
00210   /// specified function by using the dlsym function call.  As such it is only
00211   /// useful for resolving library symbols, not code generated symbols.
00212   ///
00213   /// If AbortOnFailure is false and no function with the given name is
00214   /// found, this function silently returns a null pointer. Otherwise,
00215   /// it prints a message to stderr and aborts.
00216   ///
00217   /// This function is deprecated for the MCJIT execution engine.
00218   virtual void *getPointerToNamedFunction(StringRef Name,
00219                                           bool AbortOnFailure = true) = 0;
00220 
00221   /// mapSectionAddress - map a section to its target address space value.
00222   /// Map the address of a JIT section as returned from the memory manager
00223   /// to the address in the target process as the running code will see it.
00224   /// This is the address which will be used for relocation resolution.
00225   virtual void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress) {
00226     llvm_unreachable("Re-mapping of section addresses not supported with this "
00227                      "EE!");
00228   }
00229 
00230   /// generateCodeForModule - Run code generation for the specified module and
00231   /// load it into memory.
00232   ///
00233   /// When this function has completed, all code and data for the specified
00234   /// module, and any module on which this module depends, will be generated
00235   /// and loaded into memory, but relocations will not yet have been applied
00236   /// and all memory will be readable and writable but not executable.
00237   ///
00238   /// This function is primarily useful when generating code for an external
00239   /// target, allowing the client an opportunity to remap section addresses
00240   /// before relocations are applied.  Clients that intend to execute code
00241   /// locally can use the getFunctionAddress call, which will generate code
00242   /// and apply final preparations all in one step.
00243   ///
00244   /// This method has no effect for the interpeter.
00245   virtual void generateCodeForModule(Module *M) {}
00246 
00247   /// finalizeObject - ensure the module is fully processed and is usable.
00248   ///
00249   /// It is the user-level function for completing the process of making the
00250   /// object usable for execution.  It should be called after sections within an
00251   /// object have been relocated using mapSectionAddress.  When this method is
00252   /// called the MCJIT execution engine will reapply relocations for a loaded
00253   /// object.  This method has no effect for the interpeter.
00254   virtual void finalizeObject() {}
00255 
00256   /// runStaticConstructorsDestructors - This method is used to execute all of
00257   /// the static constructors or destructors for a program.
00258   ///
00259   /// \param isDtors - Run the destructors instead of constructors.
00260   virtual void runStaticConstructorsDestructors(bool isDtors);
00261 
00262   /// This method is used to execute all of the static constructors or
00263   /// destructors for a particular module.
00264   ///
00265   /// \param isDtors - Run the destructors instead of constructors.
00266   void runStaticConstructorsDestructors(Module &module, bool isDtors);
00267 
00268 
00269   /// runFunctionAsMain - This is a helper function which wraps runFunction to
00270   /// handle the common task of starting up main with the specified argc, argv,
00271   /// and envp parameters.
00272   int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
00273                         const char * const * envp);
00274 
00275 
00276   /// addGlobalMapping - Tell the execution engine that the specified global is
00277   /// at the specified location.  This is used internally as functions are JIT'd
00278   /// and as global variables are laid out in memory.  It can and should also be
00279   /// used by clients of the EE that want to have an LLVM global overlay
00280   /// existing data in memory.  Mappings are automatically removed when their
00281   /// GlobalValue is destroyed.
00282   void addGlobalMapping(const GlobalValue *GV, void *Addr);
00283 
00284   /// clearAllGlobalMappings - Clear all global mappings and start over again,
00285   /// for use in dynamic compilation scenarios to move globals.
00286   void clearAllGlobalMappings();
00287 
00288   /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
00289   /// particular module, because it has been removed from the JIT.
00290   void clearGlobalMappingsFromModule(Module *M);
00291 
00292   /// updateGlobalMapping - Replace an existing mapping for GV with a new
00293   /// address.  This updates both maps as required.  If "Addr" is null, the
00294   /// entry for the global is removed from the mappings.  This returns the old
00295   /// value of the pointer, or null if it was not in the map.
00296   void *updateGlobalMapping(const GlobalValue *GV, void *Addr);
00297 
00298   /// getPointerToGlobalIfAvailable - This returns the address of the specified
00299   /// global value if it is has already been codegen'd, otherwise it returns
00300   /// null.
00301   ///
00302   /// This function is deprecated for the MCJIT execution engine.  It doesn't
00303   /// seem to be needed in that case, but an equivalent can be added if it is.
00304   void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
00305 
00306   /// getPointerToGlobal - This returns the address of the specified global
00307   /// value. This may involve code generation if it's a function.
00308   ///
00309   /// This function is deprecated for the MCJIT execution engine.  Use
00310   /// getGlobalValueAddress instead.
00311   void *getPointerToGlobal(const GlobalValue *GV);
00312 
00313   /// getPointerToFunction - The different EE's represent function bodies in
00314   /// different ways.  They should each implement this to say what a function
00315   /// pointer should look like.  When F is destroyed, the ExecutionEngine will
00316   /// remove its global mapping and free any machine code.  Be sure no threads
00317   /// are running inside F when that happens.
00318   ///
00319   /// This function is deprecated for the MCJIT execution engine.  Use
00320   /// getFunctionAddress instead.
00321   virtual void *getPointerToFunction(Function *F) = 0;
00322 
00323   /// getPointerToFunctionOrStub - If the specified function has been
00324   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
00325   /// a stub to implement lazy compilation if available.  See
00326   /// getPointerToFunction for the requirements on destroying F.
00327   ///
00328   /// This function is deprecated for the MCJIT execution engine.  Use
00329   /// getFunctionAddress instead.
00330   virtual void *getPointerToFunctionOrStub(Function *F) {
00331     // Default implementation, just codegen the function.
00332     return getPointerToFunction(F);
00333   }
00334 
00335   /// getGlobalValueAddress - Return the address of the specified global
00336   /// value. This may involve code generation.
00337   ///
00338   /// This function should not be called with the interpreter engine.
00339   virtual uint64_t getGlobalValueAddress(const std::string &Name) {
00340     // Default implementation for the interpreter.  MCJIT will override this.
00341     // JIT and interpreter clients should use getPointerToGlobal instead.
00342     return 0;
00343   }
00344 
00345   /// getFunctionAddress - Return the address of the specified function.
00346   /// This may involve code generation.
00347   virtual uint64_t getFunctionAddress(const std::string &Name) {
00348     // Default implementation for the interpreter.  MCJIT will override this.
00349     // Interpreter clients should use getPointerToFunction instead.
00350     return 0;
00351   }
00352 
00353   /// getGlobalValueAtAddress - Return the LLVM global value object that starts
00354   /// at the specified address.
00355   ///
00356   const GlobalValue *getGlobalValueAtAddress(void *Addr);
00357 
00358   /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
00359   /// Ptr is the address of the memory at which to store Val, cast to
00360   /// GenericValue *.  It is not a pointer to a GenericValue containing the
00361   /// address at which to store Val.
00362   void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
00363                           Type *Ty);
00364 
00365   void InitializeMemory(const Constant *Init, void *Addr);
00366 
00367   /// getOrEmitGlobalVariable - Return the address of the specified global
00368   /// variable, possibly emitting it to memory if needed.  This is used by the
00369   /// Emitter.
00370   ///
00371   /// This function is deprecated for the MCJIT execution engine.  Use
00372   /// getGlobalValueAddress instead.
00373   virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
00374     return getPointerToGlobal((const GlobalValue *)GV);
00375   }
00376 
00377   /// Registers a listener to be called back on various events within
00378   /// the JIT.  See JITEventListener.h for more details.  Does not
00379   /// take ownership of the argument.  The argument may be NULL, in
00380   /// which case these functions do nothing.
00381   virtual void RegisterJITEventListener(JITEventListener *) {}
00382   virtual void UnregisterJITEventListener(JITEventListener *) {}
00383 
00384   /// Sets the pre-compiled object cache.  The ownership of the ObjectCache is
00385   /// not changed.  Supported by MCJIT but not the interpreter.
00386   virtual void setObjectCache(ObjectCache *) {
00387     llvm_unreachable("No support for an object cache");
00388   }
00389 
00390   /// setProcessAllSections (MCJIT Only): By default, only sections that are
00391   /// "required for execution" are passed to the RTDyldMemoryManager, and other
00392   /// sections are discarded. Passing 'true' to this method will cause
00393   /// RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless
00394   /// of whether they are "required to execute" in the usual sense.
00395   ///
00396   /// Rationale: Some MCJIT clients want to be able to inspect metadata
00397   /// sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze
00398   /// performance. Passing these sections to the memory manager allows the
00399   /// client to make policy about the relevant sections, rather than having
00400   /// MCJIT do it.
00401   virtual void setProcessAllSections(bool ProcessAllSections) {
00402     llvm_unreachable("No support for ProcessAllSections option");
00403   }
00404 
00405   /// Return the target machine (if available).
00406   virtual TargetMachine *getTargetMachine() { return nullptr; }
00407 
00408   /// DisableLazyCompilation - When lazy compilation is off (the default), the
00409   /// JIT will eagerly compile every function reachable from the argument to
00410   /// getPointerToFunction.  If lazy compilation is turned on, the JIT will only
00411   /// compile the one function and emit stubs to compile the rest when they're
00412   /// first called.  If lazy compilation is turned off again while some lazy
00413   /// stubs are still around, and one of those stubs is called, the program will
00414   /// abort.
00415   ///
00416   /// In order to safely compile lazily in a threaded program, the user must
00417   /// ensure that 1) only one thread at a time can call any particular lazy
00418   /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
00419   /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
00420   /// lazy stub.  See http://llvm.org/PR5184 for details.
00421   void DisableLazyCompilation(bool Disabled = true) {
00422     CompilingLazily = !Disabled;
00423   }
00424   bool isCompilingLazily() const {
00425     return CompilingLazily;
00426   }
00427 
00428   /// DisableGVCompilation - If called, the JIT will abort if it's asked to
00429   /// allocate space and populate a GlobalVariable that is not internal to
00430   /// the module.
00431   void DisableGVCompilation(bool Disabled = true) {
00432     GVCompilationDisabled = Disabled;
00433   }
00434   bool isGVCompilationDisabled() const {
00435     return GVCompilationDisabled;
00436   }
00437 
00438   /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
00439   /// symbols with dlsym.  A client can still use InstallLazyFunctionCreator to
00440   /// resolve symbols in a custom way.
00441   void DisableSymbolSearching(bool Disabled = true) {
00442     SymbolSearchingDisabled = Disabled;
00443   }
00444   bool isSymbolSearchingDisabled() const {
00445     return SymbolSearchingDisabled;
00446   }
00447 
00448   /// Enable/Disable IR module verification.
00449   ///
00450   /// Note: Module verification is enabled by default in Debug builds, and
00451   /// disabled by default in Release. Use this method to override the default.
00452   void setVerifyModules(bool Verify) {
00453     VerifyModules = Verify;
00454   }
00455   bool getVerifyModules() const {
00456     return VerifyModules;
00457   }
00458 
00459   /// InstallLazyFunctionCreator - If an unknown function is needed, the
00460   /// specified function pointer is invoked to create it.  If it returns null,
00461   /// the JIT will abort.
00462   void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
00463     LazyFunctionCreator = P;
00464   }
00465 
00466 protected:
00467   explicit ExecutionEngine(std::unique_ptr<Module> M);
00468 
00469   void emitGlobals();
00470 
00471   void EmitGlobalVariable(const GlobalVariable *GV);
00472 
00473   GenericValue getConstantValue(const Constant *C);
00474   void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
00475                            Type *Ty);
00476 };
00477 
00478 namespace EngineKind {
00479   // These are actually bitmasks that get or-ed together.
00480   enum Kind {
00481     JIT         = 0x1,
00482     Interpreter = 0x2
00483   };
00484   const static Kind Either = (Kind)(JIT | Interpreter);
00485 }
00486 
00487 /// Builder class for ExecutionEngines. Use this by stack-allocating a builder,
00488 /// chaining the various set* methods, and terminating it with a .create()
00489 /// call.
00490 class EngineBuilder {
00491 private:
00492   std::unique_ptr<Module> M;
00493   EngineKind::Kind WhichEngine;
00494   std::string *ErrorStr;
00495   CodeGenOpt::Level OptLevel;
00496   RTDyldMemoryManager *MCJMM;
00497   JITMemoryManager *JMM;
00498   TargetOptions Options;
00499   Reloc::Model RelocModel;
00500   CodeModel::Model CMModel;
00501   std::string MArch;
00502   std::string MCPU;
00503   SmallVector<std::string, 4> MAttrs;
00504   bool VerifyModules;
00505 
00506   /// InitEngine - Does the common initialization of default options.
00507   void InitEngine();
00508 
00509 public:
00510   /// Constructor for EngineBuilder.
00511   EngineBuilder(std::unique_ptr<Module> M) : M(std::move(M)) {
00512     InitEngine();
00513   }
00514 
00515   /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
00516   /// or whichever engine works.  This option defaults to EngineKind::Either.
00517   EngineBuilder &setEngineKind(EngineKind::Kind w) {
00518     WhichEngine = w;
00519     return *this;
00520   }
00521 
00522   /// setMCJITMemoryManager - Sets the MCJIT memory manager to use. This allows
00523   /// clients to customize their memory allocation policies for the MCJIT. This
00524   /// is only appropriate for the MCJIT; setting this and configuring the builder
00525   /// to create anything other than MCJIT will cause a runtime error. If create()
00526   /// is called and is successful, the created engine takes ownership of the
00527   /// memory manager. This option defaults to NULL. Using this option nullifies
00528   /// the setJITMemoryManager() option.
00529   EngineBuilder &setMCJITMemoryManager(RTDyldMemoryManager *mcjmm) {
00530     MCJMM = mcjmm;
00531     JMM = nullptr;
00532     return *this;
00533   }
00534 
00535   /// setJITMemoryManager - Sets the JIT memory manager to use.  This allows
00536   /// clients to customize their memory allocation policies.  This is only
00537   /// appropriate for either JIT or MCJIT; setting this and configuring the
00538   /// builder to create an interpreter will cause a runtime error. If create()
00539   /// is called and is successful, the created engine takes ownership of the
00540   /// memory manager.  This option defaults to NULL. This option overrides
00541   /// setMCJITMemoryManager() as well.
00542   EngineBuilder &setJITMemoryManager(JITMemoryManager *jmm) {
00543     MCJMM = nullptr;
00544     JMM = jmm;
00545     return *this;
00546   }
00547 
00548   /// setErrorStr - Set the error string to write to on error.  This option
00549   /// defaults to NULL.
00550   EngineBuilder &setErrorStr(std::string *e) {
00551     ErrorStr = e;
00552     return *this;
00553   }
00554 
00555   /// setOptLevel - Set the optimization level for the JIT.  This option
00556   /// defaults to CodeGenOpt::Default.
00557   EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
00558     OptLevel = l;
00559     return *this;
00560   }
00561 
00562   /// setTargetOptions - Set the target options that the ExecutionEngine
00563   /// target is using. Defaults to TargetOptions().
00564   EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
00565     Options = Opts;
00566     return *this;
00567   }
00568 
00569   /// setRelocationModel - Set the relocation model that the ExecutionEngine
00570   /// target is using. Defaults to target specific default "Reloc::Default".
00571   EngineBuilder &setRelocationModel(Reloc::Model RM) {
00572     RelocModel = RM;
00573     return *this;
00574   }
00575 
00576   /// setCodeModel - Set the CodeModel that the ExecutionEngine target
00577   /// data is using. Defaults to target specific default
00578   /// "CodeModel::JITDefault".
00579   EngineBuilder &setCodeModel(CodeModel::Model M) {
00580     CMModel = M;
00581     return *this;
00582   }
00583 
00584   /// setMArch - Override the architecture set by the Module's triple.
00585   EngineBuilder &setMArch(StringRef march) {
00586     MArch.assign(march.begin(), march.end());
00587     return *this;
00588   }
00589 
00590   /// setMCPU - Target a specific cpu type.
00591   EngineBuilder &setMCPU(StringRef mcpu) {
00592     MCPU.assign(mcpu.begin(), mcpu.end());
00593     return *this;
00594   }
00595 
00596   /// setVerifyModules - Set whether the JIT implementation should verify
00597   /// IR modules during compilation.
00598   EngineBuilder &setVerifyModules(bool Verify) {
00599     VerifyModules = Verify;
00600     return *this;
00601   }
00602 
00603   /// setMAttrs - Set cpu-specific attributes.
00604   template<typename StringSequence>
00605   EngineBuilder &setMAttrs(const StringSequence &mattrs) {
00606     MAttrs.clear();
00607     MAttrs.append(mattrs.begin(), mattrs.end());
00608     return *this;
00609   }
00610 
00611   TargetMachine *selectTarget();
00612 
00613   /// selectTarget - Pick a target either via -march or by guessing the native
00614   /// arch.  Add any CPU features specified via -mcpu or -mattr.
00615   TargetMachine *selectTarget(const Triple &TargetTriple,
00616                               StringRef MArch,
00617                               StringRef MCPU,
00618                               const SmallVectorImpl<std::string>& MAttrs);
00619 
00620   ExecutionEngine *create() {
00621     return create(selectTarget());
00622   }
00623 
00624   ExecutionEngine *create(TargetMachine *TM);
00625 };
00626 
00627 // Create wrappers for C Binding types (see CBindingWrapping.h).
00628 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
00629 
00630 } // End llvm namespace
00631 
00632 #endif