Fix dependency layering issues caused by r180112.
[oota-llvm.git] / include / llvm / ExecutionEngine / ExecutionEngine.h
1 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the abstract interface that implements execution support
11 // for LLVM.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
16 #define LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
17
18 #include "llvm-c/ExecutionEngine.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/ValueMap.h"
23 #include "llvm/MC/MCCodeGenInfo.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/Mutex.h"
26 #include "llvm/Support/ValueHandle.h"
27 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/Target/TargetOptions.h"
29 #include "llvm/Wrap.h"
30 #include <map>
31 #include <string>
32 #include <vector>
33
34 namespace llvm {
35
36 struct GenericValue;
37 class Constant;
38 class ExecutionEngine;
39 class Function;
40 class GlobalVariable;
41 class GlobalValue;
42 class JITEventListener;
43 class JITMemoryManager;
44 class MachineCodeInfo;
45 class Module;
46 class MutexGuard;
47 class ObjectCache;
48 class DataLayout;
49 class Triple;
50 class Type;
51
52 /// \brief Helper class for helping synchronize access to the global address map
53 /// table.
54 class ExecutionEngineState {
55 public:
56   struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
57     typedef ExecutionEngineState *ExtraData;
58     static sys::Mutex *getMutex(ExecutionEngineState *EES);
59     static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
60     static void onRAUW(ExecutionEngineState *, const GlobalValue *,
61                        const GlobalValue *);
62   };
63
64   typedef ValueMap<const GlobalValue *, void *, AddressMapConfig>
65       GlobalAddressMapTy;
66
67 private:
68   ExecutionEngine &EE;
69
70   /// GlobalAddressMap - A mapping between LLVM global values and their
71   /// actualized version...
72   GlobalAddressMapTy GlobalAddressMap;
73
74   /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap,
75   /// used to convert raw addresses into the LLVM global value that is emitted
76   /// at the address.  This map is not computed unless getGlobalValueAtAddress
77   /// is called at some point.
78   std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap;
79
80 public:
81   ExecutionEngineState(ExecutionEngine &EE);
82
83   GlobalAddressMapTy &getGlobalAddressMap(const MutexGuard &) {
84     return GlobalAddressMap;
85   }
86
87   std::map<void*, AssertingVH<const GlobalValue> > &
88   getGlobalAddressReverseMap(const MutexGuard &) {
89     return GlobalAddressReverseMap;
90   }
91
92   /// \brief Erase an entry from the mapping table.
93   ///
94   /// \returns The address that \p ToUnmap was happed to.
95   void *RemoveMapping(const MutexGuard &, const GlobalValue *ToUnmap);
96 };
97
98 /// \brief Abstract interface for implementation execution of LLVM modules,
99 /// designed to support both interpreter and just-in-time (JIT) compiler
100 /// implementations.
101 class ExecutionEngine {
102   /// The state object holding the global address mapping, which must be
103   /// accessed synchronously.
104   //
105   // FIXME: There is no particular need the entire map needs to be
106   // synchronized.  Wouldn't a reader-writer design be better here?
107   ExecutionEngineState EEState;
108
109   /// The target data for the platform for which execution is being performed.
110   const DataLayout *TD;
111
112   /// Whether lazy JIT compilation is enabled.
113   bool CompilingLazily;
114
115   /// Whether JIT compilation of external global variables is allowed.
116   bool GVCompilationDisabled;
117
118   /// Whether the JIT should perform lookups of external symbols (e.g.,
119   /// using dlsym).
120   bool SymbolSearchingDisabled;
121
122   friend class EngineBuilder;  // To allow access to JITCtor and InterpCtor.
123
124 protected:
125   /// The list of Modules that we are JIT'ing from.  We use a SmallVector to
126   /// optimize for the case where there is only one module.
127   SmallVector<Module*, 1> Modules;
128
129   void setDataLayout(const DataLayout *td) { TD = td; }
130
131   /// getMemoryforGV - Allocate memory for a global variable.
132   virtual char *getMemoryForGV(const GlobalVariable *GV);
133
134   // To avoid having libexecutionengine depend on the JIT and interpreter
135   // libraries, the execution engine implementations set these functions to ctor
136   // pointers at startup time if they are linked in.
137   static ExecutionEngine *(*JITCtor)(
138     Module *M,
139     std::string *ErrorStr,
140     JITMemoryManager *JMM,
141     bool GVsWithCode,
142     TargetMachine *TM);
143   static ExecutionEngine *(*MCJITCtor)(
144     Module *M,
145     std::string *ErrorStr,
146     JITMemoryManager *JMM,
147     bool GVsWithCode,
148     TargetMachine *TM);
149   static ExecutionEngine *(*InterpCtor)(Module *M, std::string *ErrorStr);
150
151   /// LazyFunctionCreator - If an unknown function is needed, this function
152   /// pointer is invoked to create it.  If this returns null, the JIT will
153   /// abort.
154   void *(*LazyFunctionCreator)(const std::string &);
155
156   /// ExceptionTableRegister - If Exception Handling is set, the JIT will
157   /// register dwarf tables with this function.
158   typedef void (*EERegisterFn)(void*);
159   EERegisterFn ExceptionTableRegister;
160   EERegisterFn ExceptionTableDeregister;
161   /// This maps functions to their exception tables frames.
162   DenseMap<const Function*, void*> AllExceptionTables;
163
164
165 public:
166   /// lock - This lock protects the ExecutionEngine, JIT, JITResolver and
167   /// JITEmitter classes.  It must be held while changing the internal state of
168   /// any of those classes.
169   sys::Mutex lock;
170
171   //===--------------------------------------------------------------------===//
172   //  ExecutionEngine Startup
173   //===--------------------------------------------------------------------===//
174
175   virtual ~ExecutionEngine();
176
177   /// create - This is the factory method for creating an execution engine which
178   /// is appropriate for the current machine.  This takes ownership of the
179   /// module.
180   ///
181   /// \param GVsWithCode - Allocating globals with code breaks
182   /// freeMachineCodeForFunction and is probably unsafe and bad for performance.
183   /// However, we have clients who depend on this behavior, so we must support
184   /// it.  Eventually, when we're willing to break some backwards compatibility,
185   /// this flag should be flipped to false, so that by default
186   /// freeMachineCodeForFunction works.
187   static ExecutionEngine *create(Module *M,
188                                  bool ForceInterpreter = false,
189                                  std::string *ErrorStr = 0,
190                                  CodeGenOpt::Level OptLevel =
191                                  CodeGenOpt::Default,
192                                  bool GVsWithCode = true);
193
194   /// createJIT - This is the factory method for creating a JIT for the current
195   /// machine, it does not fall back to the interpreter.  This takes ownership
196   /// of the Module and JITMemoryManager if successful.
197   ///
198   /// Clients should make sure to initialize targets prior to calling this
199   /// function.
200   static ExecutionEngine *createJIT(Module *M,
201                                     std::string *ErrorStr = 0,
202                                     JITMemoryManager *JMM = 0,
203                                     CodeGenOpt::Level OptLevel =
204                                     CodeGenOpt::Default,
205                                     bool GVsWithCode = true,
206                                     Reloc::Model RM = Reloc::Default,
207                                     CodeModel::Model CMM =
208                                     CodeModel::JITDefault);
209
210   /// addModule - Add a Module to the list of modules that we can JIT from.
211   /// Note that this takes ownership of the Module: when the ExecutionEngine is
212   /// destroyed, it destroys the Module as well.
213   virtual void addModule(Module *M) {
214     Modules.push_back(M);
215   }
216
217   //===--------------------------------------------------------------------===//
218
219   const DataLayout *getDataLayout() const { return TD; }
220
221   /// removeModule - Remove a Module from the list of modules.  Returns true if
222   /// M is found.
223   virtual bool removeModule(Module *M);
224
225   /// FindFunctionNamed - Search all of the active modules to find the one that
226   /// defines FnName.  This is very slow operation and shouldn't be used for
227   /// general code.
228   Function *FindFunctionNamed(const char *FnName);
229
230   /// runFunction - Execute the specified function with the specified arguments,
231   /// and return the result.
232   virtual GenericValue runFunction(Function *F,
233                                 const std::vector<GenericValue> &ArgValues) = 0;
234
235   /// getPointerToNamedFunction - This method returns the address of the
236   /// specified function by using the dlsym function call.  As such it is only
237   /// useful for resolving library symbols, not code generated symbols.
238   ///
239   /// If AbortOnFailure is false and no function with the given name is
240   /// found, this function silently returns a null pointer. Otherwise,
241   /// it prints a message to stderr and aborts.
242   ///
243   virtual void *getPointerToNamedFunction(const std::string &Name,
244                                           bool AbortOnFailure = true) = 0;
245
246   /// mapSectionAddress - map a section to its target address space value.
247   /// Map the address of a JIT section as returned from the memory manager
248   /// to the address in the target process as the running code will see it.
249   /// This is the address which will be used for relocation resolution.
250   virtual void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress) {
251     llvm_unreachable("Re-mapping of section addresses not supported with this "
252                      "EE!");
253   }
254
255   // finalizeObject - This method should be called after sections within an
256   // object have been relocated using mapSectionAddress.  When this method is
257   // called the MCJIT execution engine will reapply relocations for a loaded
258   // object.  This method has no effect for the legacy JIT engine or the
259   // interpeter.
260   virtual void finalizeObject() {}
261
262   /// runStaticConstructorsDestructors - This method is used to execute all of
263   /// the static constructors or destructors for a program.
264   ///
265   /// \param isDtors - Run the destructors instead of constructors.
266   void runStaticConstructorsDestructors(bool isDtors);
267
268   /// runStaticConstructorsDestructors - This method is used to execute all of
269   /// the static constructors or destructors for a particular module.
270   ///
271   /// \param isDtors - Run the destructors instead of constructors.
272   void runStaticConstructorsDestructors(Module *module, bool isDtors);
273
274
275   /// runFunctionAsMain - This is a helper function which wraps runFunction to
276   /// handle the common task of starting up main with the specified argc, argv,
277   /// and envp parameters.
278   int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
279                         const char * const * envp);
280
281
282   /// addGlobalMapping - Tell the execution engine that the specified global is
283   /// at the specified location.  This is used internally as functions are JIT'd
284   /// and as global variables are laid out in memory.  It can and should also be
285   /// used by clients of the EE that want to have an LLVM global overlay
286   /// existing data in memory.  Mappings are automatically removed when their
287   /// GlobalValue is destroyed.
288   void addGlobalMapping(const GlobalValue *GV, void *Addr);
289
290   /// clearAllGlobalMappings - Clear all global mappings and start over again,
291   /// for use in dynamic compilation scenarios to move globals.
292   void clearAllGlobalMappings();
293
294   /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
295   /// particular module, because it has been removed from the JIT.
296   void clearGlobalMappingsFromModule(Module *M);
297
298   /// updateGlobalMapping - Replace an existing mapping for GV with a new
299   /// address.  This updates both maps as required.  If "Addr" is null, the
300   /// entry for the global is removed from the mappings.  This returns the old
301   /// value of the pointer, or null if it was not in the map.
302   void *updateGlobalMapping(const GlobalValue *GV, void *Addr);
303
304   /// getPointerToGlobalIfAvailable - This returns the address of the specified
305   /// global value if it is has already been codegen'd, otherwise it returns
306   /// null.
307   void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
308
309   /// getPointerToGlobal - This returns the address of the specified global
310   /// value. This may involve code generation if it's a function.
311   void *getPointerToGlobal(const GlobalValue *GV);
312
313   /// getPointerToFunction - The different EE's represent function bodies in
314   /// different ways.  They should each implement this to say what a function
315   /// pointer should look like.  When F is destroyed, the ExecutionEngine will
316   /// remove its global mapping and free any machine code.  Be sure no threads
317   /// are running inside F when that happens.
318   virtual void *getPointerToFunction(Function *F) = 0;
319
320   /// getPointerToBasicBlock - The different EE's represent basic blocks in
321   /// different ways.  Return the representation for a blockaddress of the
322   /// specified block.
323   virtual void *getPointerToBasicBlock(BasicBlock *BB) = 0;
324
325   /// getPointerToFunctionOrStub - If the specified function has been
326   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
327   /// a stub to implement lazy compilation if available.  See
328   /// getPointerToFunction for the requirements on destroying F.
329   virtual void *getPointerToFunctionOrStub(Function *F) {
330     // Default implementation, just codegen the function.
331     return getPointerToFunction(F);
332   }
333
334   // The JIT overrides a version that actually does this.
335   virtual void runJITOnFunction(Function *, MachineCodeInfo * = 0) { }
336
337   /// getGlobalValueAtAddress - Return the LLVM global value object that starts
338   /// at the specified address.
339   ///
340   const GlobalValue *getGlobalValueAtAddress(void *Addr);
341
342   /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
343   /// Ptr is the address of the memory at which to store Val, cast to
344   /// GenericValue *.  It is not a pointer to a GenericValue containing the
345   /// address at which to store Val.
346   void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
347                           Type *Ty);
348
349   void InitializeMemory(const Constant *Init, void *Addr);
350
351   /// recompileAndRelinkFunction - This method is used to force a function which
352   /// has already been compiled to be compiled again, possibly after it has been
353   /// modified.  Then the entry to the old copy is overwritten with a branch to
354   /// the new copy.  If there was no old copy, this acts just like
355   /// VM::getPointerToFunction().
356   virtual void *recompileAndRelinkFunction(Function *F) = 0;
357
358   /// freeMachineCodeForFunction - Release memory in the ExecutionEngine
359   /// corresponding to the machine code emitted to execute this function, useful
360   /// for garbage-collecting generated code.
361   virtual void freeMachineCodeForFunction(Function *F) = 0;
362
363   /// getOrEmitGlobalVariable - Return the address of the specified global
364   /// variable, possibly emitting it to memory if needed.  This is used by the
365   /// Emitter.
366   virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
367     return getPointerToGlobal((const GlobalValue *)GV);
368   }
369
370   /// Registers a listener to be called back on various events within
371   /// the JIT.  See JITEventListener.h for more details.  Does not
372   /// take ownership of the argument.  The argument may be NULL, in
373   /// which case these functions do nothing.
374   virtual void RegisterJITEventListener(JITEventListener *) {}
375   virtual void UnregisterJITEventListener(JITEventListener *) {}
376
377   /// Sets the pre-compiled object cache.  The ownership of the ObjectCache is
378   /// not changed.  Supported by MCJIT but not JIT.
379   virtual void setObjectCache(ObjectCache *) {
380     llvm_unreachable("No support for an object cache");
381   }
382
383   /// DisableLazyCompilation - When lazy compilation is off (the default), the
384   /// JIT will eagerly compile every function reachable from the argument to
385   /// getPointerToFunction.  If lazy compilation is turned on, the JIT will only
386   /// compile the one function and emit stubs to compile the rest when they're
387   /// first called.  If lazy compilation is turned off again while some lazy
388   /// stubs are still around, and one of those stubs is called, the program will
389   /// abort.
390   ///
391   /// In order to safely compile lazily in a threaded program, the user must
392   /// ensure that 1) only one thread at a time can call any particular lazy
393   /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
394   /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
395   /// lazy stub.  See http://llvm.org/PR5184 for details.
396   void DisableLazyCompilation(bool Disabled = true) {
397     CompilingLazily = !Disabled;
398   }
399   bool isCompilingLazily() const {
400     return CompilingLazily;
401   }
402   // Deprecated in favor of isCompilingLazily (to reduce double-negatives).
403   // Remove this in LLVM 2.8.
404   bool isLazyCompilationDisabled() const {
405     return !CompilingLazily;
406   }
407
408   /// DisableGVCompilation - If called, the JIT will abort if it's asked to
409   /// allocate space and populate a GlobalVariable that is not internal to
410   /// the module.
411   void DisableGVCompilation(bool Disabled = true) {
412     GVCompilationDisabled = Disabled;
413   }
414   bool isGVCompilationDisabled() const {
415     return GVCompilationDisabled;
416   }
417
418   /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
419   /// symbols with dlsym.  A client can still use InstallLazyFunctionCreator to
420   /// resolve symbols in a custom way.
421   void DisableSymbolSearching(bool Disabled = true) {
422     SymbolSearchingDisabled = Disabled;
423   }
424   bool isSymbolSearchingDisabled() const {
425     return SymbolSearchingDisabled;
426   }
427
428   /// InstallLazyFunctionCreator - If an unknown function is needed, the
429   /// specified function pointer is invoked to create it.  If it returns null,
430   /// the JIT will abort.
431   void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
432     LazyFunctionCreator = P;
433   }
434
435   /// InstallExceptionTableRegister - The JIT will use the given function
436   /// to register the exception tables it generates.
437   void InstallExceptionTableRegister(EERegisterFn F) {
438     ExceptionTableRegister = F;
439   }
440   void InstallExceptionTableDeregister(EERegisterFn F) {
441     ExceptionTableDeregister = F;
442   }
443
444   /// RegisterTable - Registers the given pointer as an exception table.  It
445   /// uses the ExceptionTableRegister function.
446   void RegisterTable(const Function *fn, void* res) {
447     if (ExceptionTableRegister) {
448       ExceptionTableRegister(res);
449       AllExceptionTables[fn] = res;
450     }
451   }
452
453   /// DeregisterTable - Deregisters the exception frame previously registered
454   /// for the given function.
455   void DeregisterTable(const Function *Fn) {
456     if (ExceptionTableDeregister) {
457       DenseMap<const Function*, void*>::iterator frame =
458         AllExceptionTables.find(Fn);
459       if(frame != AllExceptionTables.end()) {
460         ExceptionTableDeregister(frame->second);
461         AllExceptionTables.erase(frame);
462       }
463     }
464   }
465
466   /// DeregisterAllTables - Deregisters all previously registered pointers to an
467   /// exception tables.  It uses the ExceptionTableoDeregister function.
468   void DeregisterAllTables();
469
470 protected:
471   explicit ExecutionEngine(Module *M);
472
473   void emitGlobals();
474
475   void EmitGlobalVariable(const GlobalVariable *GV);
476
477   GenericValue getConstantValue(const Constant *C);
478   void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
479                            Type *Ty);
480 };
481
482 namespace EngineKind {
483   // These are actually bitmasks that get or-ed together.
484   enum Kind {
485     JIT         = 0x1,
486     Interpreter = 0x2
487   };
488   const static Kind Either = (Kind)(JIT | Interpreter);
489 }
490
491 /// EngineBuilder - Builder class for ExecutionEngines.  Use this by
492 /// stack-allocating a builder, chaining the various set* methods, and
493 /// terminating it with a .create() call.
494 class EngineBuilder {
495 private:
496   Module *M;
497   EngineKind::Kind WhichEngine;
498   std::string *ErrorStr;
499   CodeGenOpt::Level OptLevel;
500   JITMemoryManager *JMM;
501   bool AllocateGVsWithCode;
502   TargetOptions Options;
503   Reloc::Model RelocModel;
504   CodeModel::Model CMModel;
505   std::string MArch;
506   std::string MCPU;
507   SmallVector<std::string, 4> MAttrs;
508   bool UseMCJIT;
509
510   /// InitEngine - Does the common initialization of default options.
511   void InitEngine() {
512     WhichEngine = EngineKind::Either;
513     ErrorStr = NULL;
514     OptLevel = CodeGenOpt::Default;
515     JMM = NULL;
516     Options = TargetOptions();
517     AllocateGVsWithCode = false;
518     RelocModel = Reloc::Default;
519     CMModel = CodeModel::JITDefault;
520     UseMCJIT = false;
521   }
522
523 public:
524   /// EngineBuilder - Constructor for EngineBuilder.  If create() is called and
525   /// is successful, the created engine takes ownership of the module.
526   EngineBuilder(Module *m) : M(m) {
527     InitEngine();
528   }
529
530   /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
531   /// or whichever engine works.  This option defaults to EngineKind::Either.
532   EngineBuilder &setEngineKind(EngineKind::Kind w) {
533     WhichEngine = w;
534     return *this;
535   }
536
537   /// setJITMemoryManager - Sets the memory manager to use.  This allows
538   /// clients to customize their memory allocation policies.  If create() is
539   /// called and is successful, the created engine takes ownership of the
540   /// memory manager.  This option defaults to NULL.
541   EngineBuilder &setJITMemoryManager(JITMemoryManager *jmm) {
542     JMM = jmm;
543     return *this;
544   }
545
546   /// setErrorStr - Set the error string to write to on error.  This option
547   /// defaults to NULL.
548   EngineBuilder &setErrorStr(std::string *e) {
549     ErrorStr = e;
550     return *this;
551   }
552
553   /// setOptLevel - Set the optimization level for the JIT.  This option
554   /// defaults to CodeGenOpt::Default.
555   EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
556     OptLevel = l;
557     return *this;
558   }
559
560   /// setTargetOptions - Set the target options that the ExecutionEngine
561   /// target is using. Defaults to TargetOptions().
562   EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
563     Options = Opts;
564     return *this;
565   }
566
567   /// setRelocationModel - Set the relocation model that the ExecutionEngine
568   /// target is using. Defaults to target specific default "Reloc::Default".
569   EngineBuilder &setRelocationModel(Reloc::Model RM) {
570     RelocModel = RM;
571     return *this;
572   }
573
574   /// setCodeModel - Set the CodeModel that the ExecutionEngine target
575   /// data is using. Defaults to target specific default
576   /// "CodeModel::JITDefault".
577   EngineBuilder &setCodeModel(CodeModel::Model M) {
578     CMModel = M;
579     return *this;
580   }
581
582   /// setAllocateGVsWithCode - Sets whether global values should be allocated
583   /// into the same buffer as code.  For most applications this should be set
584   /// to false.  Allocating globals with code breaks freeMachineCodeForFunction
585   /// and is probably unsafe and bad for performance.  However, we have clients
586   /// who depend on this behavior, so we must support it.  This option defaults
587   /// to false so that users of the new API can safely use the new memory
588   /// manager and free machine code.
589   EngineBuilder &setAllocateGVsWithCode(bool a) {
590     AllocateGVsWithCode = a;
591     return *this;
592   }
593
594   /// setMArch - Override the architecture set by the Module's triple.
595   EngineBuilder &setMArch(StringRef march) {
596     MArch.assign(march.begin(), march.end());
597     return *this;
598   }
599
600   /// setMCPU - Target a specific cpu type.
601   EngineBuilder &setMCPU(StringRef mcpu) {
602     MCPU.assign(mcpu.begin(), mcpu.end());
603     return *this;
604   }
605
606   /// setUseMCJIT - Set whether the MC-JIT implementation should be used
607   /// (experimental).
608   EngineBuilder &setUseMCJIT(bool Value) {
609     UseMCJIT = Value;
610     return *this;
611   }
612
613   /// setMAttrs - Set cpu-specific attributes.
614   template<typename StringSequence>
615   EngineBuilder &setMAttrs(const StringSequence &mattrs) {
616     MAttrs.clear();
617     MAttrs.append(mattrs.begin(), mattrs.end());
618     return *this;
619   }
620
621   TargetMachine *selectTarget();
622
623   /// selectTarget - Pick a target either via -march or by guessing the native
624   /// arch.  Add any CPU features specified via -mcpu or -mattr.
625   TargetMachine *selectTarget(const Triple &TargetTriple,
626                               StringRef MArch,
627                               StringRef MCPU,
628                               const SmallVectorImpl<std::string>& MAttrs);
629
630   ExecutionEngine *create() {
631     return create(selectTarget());
632   }
633
634   ExecutionEngine *create(TargetMachine *TM);
635 };
636
637 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine,    LLVMExecutionEngineRef)
638
639 } // End llvm namespace
640
641 #endif