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_EXECUTION_ENGINE_H
00016 #define LLVM_EXECUTION_ENGINE_H
00017 
00018 #include "llvm/MC/MCCodeGenInfo.h"
00019 #include "llvm/ADT/SmallVector.h"
00020 #include "llvm/ADT/StringRef.h"
00021 #include "llvm/ADT/ValueMap.h"
00022 #include "llvm/ADT/DenseMap.h"
00023 #include "llvm/Support/ErrorHandling.h"
00024 #include "llvm/Support/ValueHandle.h"
00025 #include "llvm/Support/Mutex.h"
00026 #include "llvm/Target/TargetMachine.h"
00027 #include "llvm/Target/TargetOptions.h"
00028 #include <vector>
00029 #include <map>
00030 #include <string>
00031 
00032 namespace llvm {
00033 
00034 struct GenericValue;
00035 class Constant;
00036 class ExecutionEngine;
00037 class Function;
00038 class GlobalVariable;
00039 class GlobalValue;
00040 class JITEventListener;
00041 class JITMemoryManager;
00042 class MachineCodeInfo;
00043 class Module;
00044 class MutexGuard;
00045 class TargetData;
00046 class Triple;
00047 class Type;
00048 
00049 /// \brief Helper class for helping synchronize access to the global address map
00050 /// table.
00051 class ExecutionEngineState {
00052 public:
00053   struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
00054     typedef ExecutionEngineState *ExtraData;
00055     static sys::Mutex *getMutex(ExecutionEngineState *EES);
00056     static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
00057     static void onRAUW(ExecutionEngineState *, const GlobalValue *,
00058                        const GlobalValue *);
00059   };
00060 
00061   typedef ValueMap<const GlobalValue *, void *, AddressMapConfig>
00062       GlobalAddressMapTy;
00063 
00064 private:
00065   ExecutionEngine &EE;
00066 
00067   /// GlobalAddressMap - A mapping between LLVM global values and their
00068   /// actualized version...
00069   GlobalAddressMapTy GlobalAddressMap;
00070 
00071   /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap,
00072   /// used to convert raw addresses into the LLVM global value that is emitted
00073   /// at the address.  This map is not computed unless getGlobalValueAtAddress
00074   /// is called at some point.
00075   std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap;
00076 
00077 public:
00078   ExecutionEngineState(ExecutionEngine &EE);
00079 
00080   GlobalAddressMapTy &getGlobalAddressMap(const MutexGuard &) {
00081     return GlobalAddressMap;
00082   }
00083 
00084   std::map<void*, AssertingVH<const GlobalValue> > &
00085   getGlobalAddressReverseMap(const MutexGuard &) {
00086     return GlobalAddressReverseMap;
00087   }
00088 
00089   /// \brief Erase an entry from the mapping table.
00090   ///
00091   /// \returns The address that \arg ToUnmap was happed to.
00092   void *RemoveMapping(const MutexGuard &, const GlobalValue *ToUnmap);
00093 };
00094 
00095 /// \brief Abstract interface for implementation execution of LLVM modules,
00096 /// designed to support both interpreter and just-in-time (JIT) compiler
00097 /// implementations.
00098 class ExecutionEngine {
00099   /// The state object holding the global address mapping, which must be
00100   /// accessed synchronously.
00101   //
00102   // FIXME: There is no particular need the entire map needs to be
00103   // synchronized.  Wouldn't a reader-writer design be better here?
00104   ExecutionEngineState EEState;
00105 
00106   /// The target data for the platform for which execution is being performed.
00107   const TargetData *TD;
00108 
00109   /// Whether lazy JIT compilation is enabled.
00110   bool CompilingLazily;
00111 
00112   /// Whether JIT compilation of external global variables is allowed.
00113   bool GVCompilationDisabled;
00114 
00115   /// Whether the JIT should perform lookups of external symbols (e.g.,
00116   /// using dlsym).
00117   bool SymbolSearchingDisabled;
00118 
00119   friend class EngineBuilder;  // To allow access to JITCtor and InterpCtor.
00120 
00121 protected:
00122   /// The list of Modules that we are JIT'ing from.  We use a SmallVector to
00123   /// optimize for the case where there is only one module.
00124   SmallVector<Module*, 1> Modules;
00125 
00126   void setTargetData(const TargetData *td) { TD = td; }
00127 
00128   /// getMemoryforGV - Allocate memory for a global variable.
00129   virtual char *getMemoryForGV(const GlobalVariable *GV);
00130 
00131   // To avoid having libexecutionengine depend on the JIT and interpreter
00132   // libraries, the execution engine implementations set these functions to ctor
00133   // pointers at startup time if they are linked in.
00134   static ExecutionEngine *(*JITCtor)(
00135     Module *M,
00136     std::string *ErrorStr,
00137     JITMemoryManager *JMM,
00138     bool GVsWithCode,
00139     TargetMachine *TM);
00140   static ExecutionEngine *(*MCJITCtor)(
00141     Module *M,
00142     std::string *ErrorStr,
00143     JITMemoryManager *JMM,
00144     bool GVsWithCode,
00145     TargetMachine *TM);
00146   static ExecutionEngine *(*InterpCtor)(Module *M, std::string *ErrorStr);
00147 
00148   /// LazyFunctionCreator - If an unknown function is needed, this function
00149   /// pointer is invoked to create it.  If this returns null, the JIT will
00150   /// abort.
00151   void *(*LazyFunctionCreator)(const std::string &);
00152 
00153   /// ExceptionTableRegister - If Exception Handling is set, the JIT will
00154   /// register dwarf tables with this function.
00155   typedef void (*EERegisterFn)(void*);
00156   EERegisterFn ExceptionTableRegister;
00157   EERegisterFn ExceptionTableDeregister;
00158   /// This maps functions to their exception tables frames.
00159   DenseMap<const Function*, void*> AllExceptionTables;
00160 
00161 
00162 public:
00163   /// lock - This lock protects the ExecutionEngine, JIT, JITResolver and
00164   /// JITEmitter classes.  It must be held while changing the internal state of
00165   /// any of those classes.
00166   sys::Mutex lock;
00167 
00168   //===--------------------------------------------------------------------===//
00169   //  ExecutionEngine Startup
00170   //===--------------------------------------------------------------------===//
00171 
00172   virtual ~ExecutionEngine();
00173 
00174   /// create - This is the factory method for creating an execution engine which
00175   /// is appropriate for the current machine.  This takes ownership of the
00176   /// module.
00177   ///
00178   /// \param GVsWithCode - Allocating globals with code breaks
00179   /// freeMachineCodeForFunction and is probably unsafe and bad for performance.
00180   /// However, we have clients who depend on this behavior, so we must support
00181   /// it.  Eventually, when we're willing to break some backwards compatibility,
00182   /// this flag should be flipped to false, so that by default
00183   /// freeMachineCodeForFunction works.
00184   static ExecutionEngine *create(Module *M,
00185                                  bool ForceInterpreter = false,
00186                                  std::string *ErrorStr = 0,
00187                                  CodeGenOpt::Level OptLevel =
00188                                  CodeGenOpt::Default,
00189                                  bool GVsWithCode = true);
00190 
00191   /// createJIT - This is the factory method for creating a JIT for the current
00192   /// machine, it does not fall back to the interpreter.  This takes ownership
00193   /// of the Module and JITMemoryManager if successful.
00194   ///
00195   /// Clients should make sure to initialize targets prior to calling this
00196   /// function.
00197   static ExecutionEngine *createJIT(Module *M,
00198                                     std::string *ErrorStr = 0,
00199                                     JITMemoryManager *JMM = 0,
00200                                     CodeGenOpt::Level OptLevel =
00201                                     CodeGenOpt::Default,
00202                                     bool GVsWithCode = true,
00203                                     Reloc::Model RM = Reloc::Default,
00204                                     CodeModel::Model CMM =
00205                                     CodeModel::JITDefault);
00206 
00207   /// addModule - Add a Module to the list of modules that we can JIT from.
00208   /// Note that this takes ownership of the Module: when the ExecutionEngine is
00209   /// destroyed, it destroys the Module as well.
00210   virtual void addModule(Module *M) {
00211     Modules.push_back(M);
00212   }
00213 
00214   //===--------------------------------------------------------------------===//
00215 
00216   const TargetData *getTargetData() const { return TD; }
00217 
00218   /// removeModule - Remove a Module from the list of modules.  Returns true if
00219   /// M is found.
00220   virtual bool removeModule(Module *M);
00221 
00222   /// FindFunctionNamed - Search all of the active modules to find the one that
00223   /// defines FnName.  This is very slow operation and shouldn't be used for
00224   /// general code.
00225   Function *FindFunctionNamed(const char *FnName);
00226 
00227   /// runFunction - Execute the specified function with the specified arguments,
00228   /// and return the result.
00229   virtual GenericValue runFunction(Function *F,
00230                                 const std::vector<GenericValue> &ArgValues) = 0;
00231 
00232   /// getPointerToNamedFunction - This method returns the address of the
00233   /// specified function by using the dlsym function call.  As such it is only
00234   /// useful for resolving library symbols, not code generated symbols.
00235   ///
00236   /// If AbortOnFailure is false and no function with the given name is
00237   /// found, this function silently returns a null pointer. Otherwise,
00238   /// it prints a message to stderr and aborts.
00239   ///
00240   virtual void *getPointerToNamedFunction(const std::string &Name,
00241                                           bool AbortOnFailure = true) = 0;
00242 
00243   /// mapSectionAddress - map a section to its target address space value.
00244   /// Map the address of a JIT section as returned from the memory manager
00245   /// to the address in the target process as the running code will see it.
00246   /// This is the address which will be used for relocation resolution.
00247   virtual void mapSectionAddress(void *LocalAddress, uint64_t TargetAddress) {
00248     llvm_unreachable("Re-mapping of section addresses not supported with this "
00249                      "EE!");
00250   }
00251 
00252   /// runStaticConstructorsDestructors - This method is used to execute all of
00253   /// the static constructors or destructors for a program.
00254   ///
00255   /// \param isDtors - Run the destructors instead of constructors.
00256   void runStaticConstructorsDestructors(bool isDtors);
00257 
00258   /// runStaticConstructorsDestructors - This method is used to execute all of
00259   /// the static constructors or destructors for a particular module.
00260   ///
00261   /// \param isDtors - Run the destructors instead of constructors.
00262   void runStaticConstructorsDestructors(Module *module, bool isDtors);
00263 
00264 
00265   /// runFunctionAsMain - This is a helper function which wraps runFunction to
00266   /// handle the common task of starting up main with the specified argc, argv,
00267   /// and envp parameters.
00268   int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
00269                         const char * const * envp);
00270 
00271 
00272   /// addGlobalMapping - Tell the execution engine that the specified global is
00273   /// at the specified location.  This is used internally as functions are JIT'd
00274   /// and as global variables are laid out in memory.  It can and should also be
00275   /// used by clients of the EE that want to have an LLVM global overlay
00276   /// existing data in memory.  Mappings are automatically removed when their
00277   /// GlobalValue is destroyed.
00278   void addGlobalMapping(const GlobalValue *GV, void *Addr);
00279 
00280   /// clearAllGlobalMappings - Clear all global mappings and start over again,
00281   /// for use in dynamic compilation scenarios to move globals.
00282   void clearAllGlobalMappings();
00283 
00284   /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
00285   /// particular module, because it has been removed from the JIT.
00286   void clearGlobalMappingsFromModule(Module *M);
00287 
00288   /// updateGlobalMapping - Replace an existing mapping for GV with a new
00289   /// address.  This updates both maps as required.  If "Addr" is null, the
00290   /// entry for the global is removed from the mappings.  This returns the old
00291   /// value of the pointer, or null if it was not in the map.
00292   void *updateGlobalMapping(const GlobalValue *GV, void *Addr);
00293 
00294   /// getPointerToGlobalIfAvailable - This returns the address of the specified
00295   /// global value if it is has already been codegen'd, otherwise it returns
00296   /// null.
00297   void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
00298 
00299   /// getPointerToGlobal - This returns the address of the specified global
00300   /// value. This may involve code generation if it's a function.
00301   void *getPointerToGlobal(const GlobalValue *GV);
00302 
00303   /// getPointerToFunction - The different EE's represent function bodies in
00304   /// different ways.  They should each implement this to say what a function
00305   /// pointer should look like.  When F is destroyed, the ExecutionEngine will
00306   /// remove its global mapping and free any machine code.  Be sure no threads
00307   /// are running inside F when that happens.
00308   virtual void *getPointerToFunction(Function *F) = 0;
00309 
00310   /// getPointerToBasicBlock - The different EE's represent basic blocks in
00311   /// different ways.  Return the representation for a blockaddress of the
00312   /// specified block.
00313   virtual void *getPointerToBasicBlock(BasicBlock *BB) = 0;
00314 
00315   /// getPointerToFunctionOrStub - If the specified function has been
00316   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
00317   /// a stub to implement lazy compilation if available.  See
00318   /// getPointerToFunction for the requirements on destroying F.
00319   virtual void *getPointerToFunctionOrStub(Function *F) {
00320     // Default implementation, just codegen the function.
00321     return getPointerToFunction(F);
00322   }
00323 
00324   // The JIT overrides a version that actually does this.
00325   virtual void runJITOnFunction(Function *, MachineCodeInfo * = 0) { }
00326 
00327   /// getGlobalValueAtAddress - Return the LLVM global value object that starts
00328   /// at the specified address.
00329   ///
00330   const GlobalValue *getGlobalValueAtAddress(void *Addr);
00331 
00332   /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
00333   /// Ptr is the address of the memory at which to store Val, cast to
00334   /// GenericValue *.  It is not a pointer to a GenericValue containing the
00335   /// address at which to store Val.
00336   void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
00337                           Type *Ty);
00338 
00339   void InitializeMemory(const Constant *Init, void *Addr);
00340 
00341   /// recompileAndRelinkFunction - This method is used to force a function which
00342   /// has already been compiled to be compiled again, possibly after it has been
00343   /// modified.  Then the entry to the old copy is overwritten with a branch to
00344   /// the new copy.  If there was no old copy, this acts just like
00345   /// VM::getPointerToFunction().
00346   virtual void *recompileAndRelinkFunction(Function *F) = 0;
00347 
00348   /// freeMachineCodeForFunction - Release memory in the ExecutionEngine
00349   /// corresponding to the machine code emitted to execute this function, useful
00350   /// for garbage-collecting generated code.
00351   virtual void freeMachineCodeForFunction(Function *F) = 0;
00352 
00353   /// getOrEmitGlobalVariable - Return the address of the specified global
00354   /// variable, possibly emitting it to memory if needed.  This is used by the
00355   /// Emitter.
00356   virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
00357     return getPointerToGlobal((GlobalValue*)GV);
00358   }
00359 
00360   /// Registers a listener to be called back on various events within
00361   /// the JIT.  See JITEventListener.h for more details.  Does not
00362   /// take ownership of the argument.  The argument may be NULL, in
00363   /// which case these functions do nothing.
00364   virtual void RegisterJITEventListener(JITEventListener *) {}
00365   virtual void UnregisterJITEventListener(JITEventListener *) {}
00366 
00367   /// DisableLazyCompilation - When lazy compilation is off (the default), the
00368   /// JIT will eagerly compile every function reachable from the argument to
00369   /// getPointerToFunction.  If lazy compilation is turned on, the JIT will only
00370   /// compile the one function and emit stubs to compile the rest when they're
00371   /// first called.  If lazy compilation is turned off again while some lazy
00372   /// stubs are still around, and one of those stubs is called, the program will
00373   /// abort.
00374   ///
00375   /// In order to safely compile lazily in a threaded program, the user must
00376   /// ensure that 1) only one thread at a time can call any particular lazy
00377   /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
00378   /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
00379   /// lazy stub.  See http://llvm.org/PR5184 for details.
00380   void DisableLazyCompilation(bool Disabled = true) {
00381     CompilingLazily = !Disabled;
00382   }
00383   bool isCompilingLazily() const {
00384     return CompilingLazily;
00385   }
00386   // Deprecated in favor of isCompilingLazily (to reduce double-negatives).
00387   // Remove this in LLVM 2.8.
00388   bool isLazyCompilationDisabled() const {
00389     return !CompilingLazily;
00390   }
00391 
00392   /// DisableGVCompilation - If called, the JIT will abort if it's asked to
00393   /// allocate space and populate a GlobalVariable that is not internal to
00394   /// the module.
00395   void DisableGVCompilation(bool Disabled = true) {
00396     GVCompilationDisabled = Disabled;
00397   }
00398   bool isGVCompilationDisabled() const {
00399     return GVCompilationDisabled;
00400   }
00401 
00402   /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
00403   /// symbols with dlsym.  A client can still use InstallLazyFunctionCreator to
00404   /// resolve symbols in a custom way.
00405   void DisableSymbolSearching(bool Disabled = true) {
00406     SymbolSearchingDisabled = Disabled;
00407   }
00408   bool isSymbolSearchingDisabled() const {
00409     return SymbolSearchingDisabled;
00410   }
00411 
00412   /// InstallLazyFunctionCreator - If an unknown function is needed, the
00413   /// specified function pointer is invoked to create it.  If it returns null,
00414   /// the JIT will abort.
00415   void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
00416     LazyFunctionCreator = P;
00417   }
00418 
00419   /// InstallExceptionTableRegister - The JIT will use the given function
00420   /// to register the exception tables it generates.
00421   void InstallExceptionTableRegister(EERegisterFn F) {
00422     ExceptionTableRegister = F;
00423   }
00424   void InstallExceptionTableDeregister(EERegisterFn F) {
00425     ExceptionTableDeregister = F;
00426   }
00427 
00428   /// RegisterTable - Registers the given pointer as an exception table.  It
00429   /// uses the ExceptionTableRegister function.
00430   void RegisterTable(const Function *fn, void* res) {
00431     if (ExceptionTableRegister) {
00432       ExceptionTableRegister(res);
00433       AllExceptionTables[fn] = res;
00434     }
00435   }
00436 
00437   /// DeregisterTable - Deregisters the exception frame previously registered
00438   /// for the given function.
00439   void DeregisterTable(const Function *Fn) {
00440     if (ExceptionTableDeregister) {
00441       DenseMap<const Function*, void*>::iterator frame =
00442         AllExceptionTables.find(Fn);
00443       if(frame != AllExceptionTables.end()) {
00444         ExceptionTableDeregister(frame->second);
00445         AllExceptionTables.erase(frame);
00446       }
00447     }
00448   }
00449 
00450   /// DeregisterAllTables - Deregisters all previously registered pointers to an
00451   /// exception tables.  It uses the ExceptionTableoDeregister function.
00452   void DeregisterAllTables();
00453 
00454 protected:
00455   explicit ExecutionEngine(Module *M);
00456 
00457   void emitGlobals();
00458 
00459   void EmitGlobalVariable(const GlobalVariable *GV);
00460 
00461   GenericValue getConstantValue(const Constant *C);
00462   void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
00463                            Type *Ty);
00464 };
00465 
00466 namespace EngineKind {
00467   // These are actually bitmasks that get or-ed together.
00468   enum Kind {
00469     JIT         = 0x1,
00470     Interpreter = 0x2
00471   };
00472   const static Kind Either = (Kind)(JIT | Interpreter);
00473 }
00474 
00475 /// EngineBuilder - Builder class for ExecutionEngines.  Use this by
00476 /// stack-allocating a builder, chaining the various set* methods, and
00477 /// terminating it with a .create() call.
00478 class EngineBuilder {
00479 private:
00480   Module *M;
00481   EngineKind::Kind WhichEngine;
00482   std::string *ErrorStr;
00483   CodeGenOpt::Level OptLevel;
00484   JITMemoryManager *JMM;
00485   bool AllocateGVsWithCode;
00486   TargetOptions Options;
00487   Reloc::Model RelocModel;
00488   CodeModel::Model CMModel;
00489   std::string MArch;
00490   std::string MCPU;
00491   SmallVector<std::string, 4> MAttrs;
00492   bool UseMCJIT;
00493 
00494   /// InitEngine - Does the common initialization of default options.
00495   void InitEngine() {
00496     WhichEngine = EngineKind::Either;
00497     ErrorStr = NULL;
00498     OptLevel = CodeGenOpt::Default;
00499     JMM = NULL;
00500     Options = TargetOptions();
00501     AllocateGVsWithCode = false;
00502     RelocModel = Reloc::Default;
00503     CMModel = CodeModel::JITDefault;
00504     UseMCJIT = false;
00505   }
00506 
00507 public:
00508   /// EngineBuilder - Constructor for EngineBuilder.  If create() is called and
00509   /// is successful, the created engine takes ownership of the module.
00510   EngineBuilder(Module *m) : M(m) {
00511     InitEngine();
00512   }
00513 
00514   /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
00515   /// or whichever engine works.  This option defaults to EngineKind::Either.
00516   EngineBuilder &setEngineKind(EngineKind::Kind w) {
00517     WhichEngine = w;
00518     return *this;
00519   }
00520 
00521   /// setJITMemoryManager - Sets the memory manager to use.  This allows
00522   /// clients to customize their memory allocation policies.  If create() is
00523   /// called and is successful, the created engine takes ownership of the
00524   /// memory manager.  This option defaults to NULL.
00525   EngineBuilder &setJITMemoryManager(JITMemoryManager *jmm) {
00526     JMM = jmm;
00527     return *this;
00528   }
00529 
00530   /// setErrorStr - Set the error string to write to on error.  This option
00531   /// defaults to NULL.
00532   EngineBuilder &setErrorStr(std::string *e) {
00533     ErrorStr = e;
00534     return *this;
00535   }
00536 
00537   /// setOptLevel - Set the optimization level for the JIT.  This option
00538   /// defaults to CodeGenOpt::Default.
00539   EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
00540     OptLevel = l;
00541     return *this;
00542   }
00543 
00544   /// setTargetOptions - Set the target options that the ExecutionEngine
00545   /// target is using. Defaults to TargetOptions().
00546   EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
00547     Options = Opts;
00548     return *this;
00549   }
00550 
00551   /// setRelocationModel - Set the relocation model that the ExecutionEngine
00552   /// target is using. Defaults to target specific default "Reloc::Default".
00553   EngineBuilder &setRelocationModel(Reloc::Model RM) {
00554     RelocModel = RM;
00555     return *this;
00556   }
00557 
00558   /// setCodeModel - Set the CodeModel that the ExecutionEngine target
00559   /// data is using. Defaults to target specific default
00560   /// "CodeModel::JITDefault".
00561   EngineBuilder &setCodeModel(CodeModel::Model M) {
00562     CMModel = M;
00563     return *this;
00564   }
00565 
00566   /// setAllocateGVsWithCode - Sets whether global values should be allocated
00567   /// into the same buffer as code.  For most applications this should be set
00568   /// to false.  Allocating globals with code breaks freeMachineCodeForFunction
00569   /// and is probably unsafe and bad for performance.  However, we have clients
00570   /// who depend on this behavior, so we must support it.  This option defaults
00571   /// to false so that users of the new API can safely use the new memory
00572   /// manager and free machine code.
00573   EngineBuilder &setAllocateGVsWithCode(bool a) {
00574     AllocateGVsWithCode = a;
00575     return *this;
00576   }
00577 
00578   /// setMArch - Override the architecture set by the Module's triple.
00579   EngineBuilder &setMArch(StringRef march) {
00580     MArch.assign(march.begin(), march.end());
00581     return *this;
00582   }
00583 
00584   /// setMCPU - Target a specific cpu type.
00585   EngineBuilder &setMCPU(StringRef mcpu) {
00586     MCPU.assign(mcpu.begin(), mcpu.end());
00587     return *this;
00588   }
00589 
00590   /// setUseMCJIT - Set whether the MC-JIT implementation should be used
00591   /// (experimental).
00592   EngineBuilder &setUseMCJIT(bool Value) {
00593     UseMCJIT = Value;
00594     return *this;
00595   }
00596 
00597   /// setMAttrs - Set cpu-specific attributes.
00598   template<typename StringSequence>
00599   EngineBuilder &setMAttrs(const StringSequence &mattrs) {
00600     MAttrs.clear();
00601     MAttrs.append(mattrs.begin(), mattrs.end());
00602     return *this;
00603   }
00604 
00605   TargetMachine *selectTarget();
00606 
00607   /// selectTarget - Pick a target either via -march or by guessing the native
00608   /// arch.  Add any CPU features specified via -mcpu or -mattr.
00609   TargetMachine *selectTarget(const Triple &TargetTriple,
00610                               StringRef MArch,
00611                               StringRef MCPU,
00612                               const SmallVectorImpl<std::string>& MAttrs);
00613 
00614   ExecutionEngine *create() {
00615     return create(selectTarget());
00616   }
00617 
00618   ExecutionEngine *create(TargetMachine *TM);
00619 };
00620 
00621 } // End llvm namespace
00622 
00623 #endif