unique_ptrify passing the TargetMachine to ExecutionEngine::MCJITCtor
[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/SmallVector.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/IR/ValueHandle.h"
23 #include "llvm/IR/ValueMap.h"
24 #include "llvm/MC/MCCodeGenInfo.h"
25 #include "llvm/Object/Binary.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/Mutex.h"
28 #include "llvm/Target/TargetMachine.h"
29 #include "llvm/Target/TargetOptions.h"
30 #include <map>
31 #include <string>
32 #include <vector>
33
34 namespace llvm {
35
36 struct GenericValue;
37 class Constant;
38 class DataLayout;
39 class ExecutionEngine;
40 class Function;
41 class GlobalVariable;
42 class GlobalValue;
43 class JITEventListener;
44 class JITMemoryManager;
45 class MachineCodeInfo;
46 class MutexGuard;
47 class ObjectCache;
48 class RTDyldMemoryManager;
49 class Triple;
50 class Type;
51
52 namespace object {
53   class Archive;
54   class ObjectFile;
55 }
56
57 /// \brief Helper class for helping synchronize access to the global address map
58 /// table.  Access to this class should be serialized under a mutex.
59 class ExecutionEngineState {
60 public:
61   struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
62     typedef ExecutionEngineState *ExtraData;
63     static sys::Mutex *getMutex(ExecutionEngineState *EES);
64     static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
65     static void onRAUW(ExecutionEngineState *, const GlobalValue *,
66                        const GlobalValue *);
67   };
68
69   typedef ValueMap<const GlobalValue *, void *, AddressMapConfig>
70       GlobalAddressMapTy;
71
72 private:
73   ExecutionEngine &EE;
74
75   /// GlobalAddressMap - A mapping between LLVM global values and their
76   /// actualized version...
77   GlobalAddressMapTy GlobalAddressMap;
78
79   /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap,
80   /// used to convert raw addresses into the LLVM global value that is emitted
81   /// at the address.  This map is not computed unless getGlobalValueAtAddress
82   /// is called at some point.
83   std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap;
84
85 public:
86   ExecutionEngineState(ExecutionEngine &EE);
87
88   GlobalAddressMapTy &getGlobalAddressMap() {
89     return GlobalAddressMap;
90   }
91
92   std::map<void*, AssertingVH<const GlobalValue> > &
93   getGlobalAddressReverseMap() {
94     return GlobalAddressReverseMap;
95   }
96
97   /// \brief Erase an entry from the mapping table.
98   ///
99   /// \returns The address that \p ToUnmap was happed to.
100   void *RemoveMapping(const GlobalValue *ToUnmap);
101 };
102
103 /// \brief Abstract interface for implementation execution of LLVM modules,
104 /// designed to support both interpreter and just-in-time (JIT) compiler
105 /// implementations.
106 class ExecutionEngine {
107   /// The state object holding the global address mapping, which must be
108   /// accessed synchronously.
109   //
110   // FIXME: There is no particular need the entire map needs to be
111   // synchronized.  Wouldn't a reader-writer design be better here?
112   ExecutionEngineState EEState;
113
114   /// The target data for the platform for which execution is being performed.
115   const DataLayout *DL;
116
117   /// Whether lazy JIT compilation is enabled.
118   bool CompilingLazily;
119
120   /// Whether JIT compilation of external global variables is allowed.
121   bool GVCompilationDisabled;
122
123   /// Whether the JIT should perform lookups of external symbols (e.g.,
124   /// using dlsym).
125   bool SymbolSearchingDisabled;
126
127   /// Whether the JIT should verify IR modules during compilation.
128   bool VerifyModules;
129
130   friend class EngineBuilder;  // To allow access to JITCtor and InterpCtor.
131
132 protected:
133   /// The list of Modules that we are JIT'ing from.  We use a SmallVector to
134   /// optimize for the case where there is only one module.
135   SmallVector<std::unique_ptr<Module>, 1> Modules;
136
137   void setDataLayout(const DataLayout *Val) { DL = Val; }
138
139   /// getMemoryforGV - Allocate memory for a global variable.
140   virtual char *getMemoryForGV(const GlobalVariable *GV);
141
142   static ExecutionEngine *(*MCJITCtor)(std::unique_ptr<Module> M,
143                                        std::string *ErrorStr,
144                                        RTDyldMemoryManager *MCJMM,
145                                        std::unique_ptr<TargetMachine> TM);
146   static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M,
147                                         std::string *ErrorStr);
148
149   /// LazyFunctionCreator - If an unknown function is needed, this function
150   /// pointer is invoked to create it.  If this returns null, the JIT will
151   /// abort.
152   void *(*LazyFunctionCreator)(const std::string &);
153
154 public:
155   /// lock - This lock protects the ExecutionEngine, MCJIT, JIT, JITResolver and
156   /// JITEmitter classes.  It must be held while changing the internal state of
157   /// any of those classes.
158   sys::Mutex lock;
159
160   //===--------------------------------------------------------------------===//
161   //  ExecutionEngine Startup
162   //===--------------------------------------------------------------------===//
163
164   virtual ~ExecutionEngine();
165
166   /// Add a Module to the list of modules that we can JIT from.
167   virtual void addModule(std::unique_ptr<Module> M) {
168     Modules.push_back(std::move(M));
169   }
170
171   /// addObjectFile - Add an ObjectFile to the execution engine.
172   ///
173   /// This method is only supported by MCJIT.  MCJIT will immediately load the
174   /// object into memory and adds its symbols to the list used to resolve
175   /// external symbols while preparing other objects for execution.
176   ///
177   /// Objects added using this function will not be made executable until
178   /// needed by another object.
179   ///
180   /// MCJIT will take ownership of the ObjectFile.
181   virtual void addObjectFile(std::unique_ptr<object::ObjectFile> O);
182   virtual void addObjectFile(object::OwningBinary<object::ObjectFile> O);
183
184   /// addArchive - Add an Archive to the execution engine.
185   ///
186   /// This method is only supported by MCJIT.  MCJIT will use the archive to
187   /// resolve external symbols in objects it is loading.  If a symbol is found
188   /// in the Archive the contained object file will be extracted (in memory)
189   /// and loaded for possible execution.
190   virtual void addArchive(object::OwningBinary<object::Archive> A);
191
192   //===--------------------------------------------------------------------===//
193
194   const DataLayout *getDataLayout() const { return DL; }
195
196   /// removeModule - Remove a Module from the list of modules.  Returns true if
197   /// M is found.
198   virtual bool removeModule(Module *M);
199
200   /// FindFunctionNamed - Search all of the active modules to find the one that
201   /// defines FnName.  This is very slow operation and shouldn't be used for
202   /// general code.
203   virtual Function *FindFunctionNamed(const char *FnName);
204
205   /// runFunction - Execute the specified function with the specified arguments,
206   /// and return the result.
207   virtual GenericValue runFunction(Function *F,
208                                 const std::vector<GenericValue> &ArgValues) = 0;
209
210   /// getPointerToNamedFunction - This method returns the address of the
211   /// specified function by using the dlsym function call.  As such it is only
212   /// useful for resolving library symbols, not code generated symbols.
213   ///
214   /// If AbortOnFailure is false and no function with the given name is
215   /// found, this function silently returns a null pointer. Otherwise,
216   /// it prints a message to stderr and aborts.
217   ///
218   /// This function is deprecated for the MCJIT execution engine.
219   ///
220   /// FIXME: the JIT and MCJIT interfaces should be disentangled or united
221   /// again, if possible.
222   ///
223   virtual void *getPointerToNamedFunction(const std::string &Name,
224                                           bool AbortOnFailure = true) = 0;
225
226   /// mapSectionAddress - map a section to its target address space value.
227   /// Map the address of a JIT section as returned from the memory manager
228   /// to the address in the target process as the running code will see it.
229   /// This is the address which will be used for relocation resolution.
230   virtual void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress) {
231     llvm_unreachable("Re-mapping of section addresses not supported with this "
232                      "EE!");
233   }
234
235   /// generateCodeForModule - Run code generationen for the specified module and
236   /// load it into memory.
237   ///
238   /// When this function has completed, all code and data for the specified
239   /// module, and any module on which this module depends, will be generated
240   /// and loaded into memory, but relocations will not yet have been applied
241   /// and all memory will be readable and writable but not executable.
242   ///
243   /// This function is primarily useful when generating code for an external
244   /// target, allowing the client an opportunity to remap section addresses
245   /// before relocations are applied.  Clients that intend to execute code
246   /// locally can use the getFunctionAddress call, which will generate code
247   /// and apply final preparations all in one step.
248   ///
249   /// This method has no effect for the legacy JIT engine or the interpeter.
250   virtual void generateCodeForModule(Module *M) {}
251
252   /// finalizeObject - ensure the module is fully processed and is usable.
253   ///
254   /// It is the user-level function for completing the process of making the
255   /// object usable for execution.  It 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   virtual void runStaticConstructorsDestructors(bool isDtors);
267
268   /// This method is used to execute all of the static constructors or
269   /// 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   ///
308   /// This function is deprecated for the MCJIT execution engine.  It doesn't
309   /// seem to be needed in that case, but an equivalent can be added if it is.
310   void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
311
312   /// getPointerToGlobal - This returns the address of the specified global
313   /// value. This may involve code generation if it's a function.
314   ///
315   /// This function is deprecated for the MCJIT execution engine.  Use
316   /// getGlobalValueAddress instead.
317   void *getPointerToGlobal(const GlobalValue *GV);
318
319   /// getPointerToFunction - The different EE's represent function bodies in
320   /// different ways.  They should each implement this to say what a function
321   /// pointer should look like.  When F is destroyed, the ExecutionEngine will
322   /// remove its global mapping and free any machine code.  Be sure no threads
323   /// are running inside F when that happens.
324   ///
325   /// This function is deprecated for the MCJIT execution engine.  Use
326   /// getFunctionAddress instead.
327   virtual void *getPointerToFunction(Function *F) = 0;
328
329   /// getPointerToFunctionOrStub - If the specified function has been
330   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
331   /// a stub to implement lazy compilation if available.  See
332   /// getPointerToFunction for the requirements on destroying F.
333   ///
334   /// This function is deprecated for the MCJIT execution engine.  Use
335   /// getFunctionAddress instead.
336   virtual void *getPointerToFunctionOrStub(Function *F) {
337     // Default implementation, just codegen the function.
338     return getPointerToFunction(F);
339   }
340
341   /// getGlobalValueAddress - Return the address of the specified global
342   /// value. This may involve code generation.
343   ///
344   /// This function should not be called with the JIT or interpreter engines.
345   virtual uint64_t getGlobalValueAddress(const std::string &Name) {
346     // Default implementation for JIT and interpreter.  MCJIT will override this.
347     // JIT and interpreter clients should use getPointerToGlobal instead.
348     return 0;
349   }
350
351   /// getFunctionAddress - Return the address of the specified function.
352   /// This may involve code generation.
353   virtual uint64_t getFunctionAddress(const std::string &Name) {
354     // Default implementation for JIT and interpreter.  MCJIT will override this.
355     // JIT and interpreter clients should use getPointerToFunction instead.
356     return 0;
357   }
358
359   // The JIT overrides a version that actually does this.
360   virtual void runJITOnFunction(Function *, MachineCodeInfo * = nullptr) { }
361
362   /// getGlobalValueAtAddress - Return the LLVM global value object that starts
363   /// at the specified address.
364   ///
365   const GlobalValue *getGlobalValueAtAddress(void *Addr);
366
367   /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
368   /// Ptr is the address of the memory at which to store Val, cast to
369   /// GenericValue *.  It is not a pointer to a GenericValue containing the
370   /// address at which to store Val.
371   void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
372                           Type *Ty);
373
374   void InitializeMemory(const Constant *Init, void *Addr);
375
376   /// getOrEmitGlobalVariable - Return the address of the specified global
377   /// variable, possibly emitting it to memory if needed.  This is used by the
378   /// Emitter.
379   ///
380   /// This function is deprecated for the MCJIT execution engine.  Use
381   /// getGlobalValueAddress instead.
382   virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
383     return getPointerToGlobal((const GlobalValue *)GV);
384   }
385
386   /// Registers a listener to be called back on various events within
387   /// the JIT.  See JITEventListener.h for more details.  Does not
388   /// take ownership of the argument.  The argument may be NULL, in
389   /// which case these functions do nothing.
390   virtual void RegisterJITEventListener(JITEventListener *) {}
391   virtual void UnregisterJITEventListener(JITEventListener *) {}
392
393   /// Sets the pre-compiled object cache.  The ownership of the ObjectCache is
394   /// not changed.  Supported by MCJIT but not JIT.
395   virtual void setObjectCache(ObjectCache *) {
396     llvm_unreachable("No support for an object cache");
397   }
398
399   /// setProcessAllSections (MCJIT Only): By default, only sections that are
400   /// "required for execution" are passed to the RTDyldMemoryManager, and other
401   /// sections are discarded. Passing 'true' to this method will cause
402   /// RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless
403   /// of whether they are "required to execute" in the usual sense.
404   ///
405   /// Rationale: Some MCJIT clients want to be able to inspect metadata
406   /// sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze
407   /// performance. Passing these sections to the memory manager allows the
408   /// client to make policy about the relevant sections, rather than having
409   /// MCJIT do it.
410   virtual void setProcessAllSections(bool ProcessAllSections) {
411     llvm_unreachable("No support for ProcessAllSections option");
412   }
413
414   /// Return the target machine (if available).
415   virtual TargetMachine *getTargetMachine() { return nullptr; }
416
417   /// DisableLazyCompilation - When lazy compilation is off (the default), the
418   /// JIT will eagerly compile every function reachable from the argument to
419   /// getPointerToFunction.  If lazy compilation is turned on, the JIT will only
420   /// compile the one function and emit stubs to compile the rest when they're
421   /// first called.  If lazy compilation is turned off again while some lazy
422   /// stubs are still around, and one of those stubs is called, the program will
423   /// abort.
424   ///
425   /// In order to safely compile lazily in a threaded program, the user must
426   /// ensure that 1) only one thread at a time can call any particular lazy
427   /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
428   /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
429   /// lazy stub.  See http://llvm.org/PR5184 for details.
430   void DisableLazyCompilation(bool Disabled = true) {
431     CompilingLazily = !Disabled;
432   }
433   bool isCompilingLazily() const {
434     return CompilingLazily;
435   }
436   // Deprecated in favor of isCompilingLazily (to reduce double-negatives).
437   // Remove this in LLVM 2.8.
438   bool isLazyCompilationDisabled() const {
439     return !CompilingLazily;
440   }
441
442   /// DisableGVCompilation - If called, the JIT will abort if it's asked to
443   /// allocate space and populate a GlobalVariable that is not internal to
444   /// the module.
445   void DisableGVCompilation(bool Disabled = true) {
446     GVCompilationDisabled = Disabled;
447   }
448   bool isGVCompilationDisabled() const {
449     return GVCompilationDisabled;
450   }
451
452   /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
453   /// symbols with dlsym.  A client can still use InstallLazyFunctionCreator to
454   /// resolve symbols in a custom way.
455   void DisableSymbolSearching(bool Disabled = true) {
456     SymbolSearchingDisabled = Disabled;
457   }
458   bool isSymbolSearchingDisabled() const {
459     return SymbolSearchingDisabled;
460   }
461
462   /// Enable/Disable IR module verification.
463   ///
464   /// Note: Module verification is enabled by default in Debug builds, and
465   /// disabled by default in Release. Use this method to override the default.
466   void setVerifyModules(bool Verify) {
467     VerifyModules = Verify;
468   }
469   bool getVerifyModules() const {
470     return VerifyModules;
471   }
472
473   /// InstallLazyFunctionCreator - If an unknown function is needed, the
474   /// specified function pointer is invoked to create it.  If it returns null,
475   /// the JIT will abort.
476   void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
477     LazyFunctionCreator = P;
478   }
479
480 protected:
481   explicit ExecutionEngine(std::unique_ptr<Module> M);
482
483   void emitGlobals();
484
485   void EmitGlobalVariable(const GlobalVariable *GV);
486
487   GenericValue getConstantValue(const Constant *C);
488   void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
489                            Type *Ty);
490 };
491
492 namespace EngineKind {
493   // These are actually bitmasks that get or-ed together.
494   enum Kind {
495     JIT         = 0x1,
496     Interpreter = 0x2
497   };
498   const static Kind Either = (Kind)(JIT | Interpreter);
499 }
500
501 /// Builder class for ExecutionEngines. Use this by stack-allocating a builder,
502 /// chaining the various set* methods, and terminating it with a .create()
503 /// call.
504 class EngineBuilder {
505 private:
506   std::unique_ptr<Module> M;
507   EngineKind::Kind WhichEngine;
508   std::string *ErrorStr;
509   CodeGenOpt::Level OptLevel;
510   RTDyldMemoryManager *MCJMM;
511   JITMemoryManager *JMM;
512   TargetOptions Options;
513   Reloc::Model RelocModel;
514   CodeModel::Model CMModel;
515   std::string MArch;
516   std::string MCPU;
517   SmallVector<std::string, 4> MAttrs;
518   bool VerifyModules;
519
520   /// InitEngine - Does the common initialization of default options.
521   void InitEngine();
522
523 public:
524   /// Constructor for EngineBuilder.
525   EngineBuilder(std::unique_ptr<Module> M) : M(std::move(M)) {
526     InitEngine();
527   }
528
529   /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
530   /// or whichever engine works.  This option defaults to EngineKind::Either.
531   EngineBuilder &setEngineKind(EngineKind::Kind w) {
532     WhichEngine = w;
533     return *this;
534   }
535
536   /// setMCJITMemoryManager - Sets the MCJIT memory manager to use. This allows
537   /// clients to customize their memory allocation policies for the MCJIT. This
538   /// is only appropriate for the MCJIT; setting this and configuring the builder
539   /// to create anything other than MCJIT will cause a runtime error. If create()
540   /// is called and is successful, the created engine takes ownership of the
541   /// memory manager. This option defaults to NULL. Using this option nullifies
542   /// the setJITMemoryManager() option.
543   EngineBuilder &setMCJITMemoryManager(RTDyldMemoryManager *mcjmm) {
544     MCJMM = mcjmm;
545     JMM = nullptr;
546     return *this;
547   }
548
549   /// setJITMemoryManager - Sets the JIT memory manager to use.  This allows
550   /// clients to customize their memory allocation policies.  This is only
551   /// appropriate for either JIT or MCJIT; setting this and configuring the
552   /// builder to create an interpreter will cause a runtime error. If create()
553   /// is called and is successful, the created engine takes ownership of the
554   /// memory manager.  This option defaults to NULL. This option overrides
555   /// setMCJITMemoryManager() as well.
556   EngineBuilder &setJITMemoryManager(JITMemoryManager *jmm) {
557     MCJMM = nullptr;
558     JMM = jmm;
559     return *this;
560   }
561
562   /// setErrorStr - Set the error string to write to on error.  This option
563   /// defaults to NULL.
564   EngineBuilder &setErrorStr(std::string *e) {
565     ErrorStr = e;
566     return *this;
567   }
568
569   /// setOptLevel - Set the optimization level for the JIT.  This option
570   /// defaults to CodeGenOpt::Default.
571   EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
572     OptLevel = l;
573     return *this;
574   }
575
576   /// setTargetOptions - Set the target options that the ExecutionEngine
577   /// target is using. Defaults to TargetOptions().
578   EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
579     Options = Opts;
580     return *this;
581   }
582
583   /// setRelocationModel - Set the relocation model that the ExecutionEngine
584   /// target is using. Defaults to target specific default "Reloc::Default".
585   EngineBuilder &setRelocationModel(Reloc::Model RM) {
586     RelocModel = RM;
587     return *this;
588   }
589
590   /// setCodeModel - Set the CodeModel that the ExecutionEngine target
591   /// data is using. Defaults to target specific default
592   /// "CodeModel::JITDefault".
593   EngineBuilder &setCodeModel(CodeModel::Model M) {
594     CMModel = M;
595     return *this;
596   }
597
598   /// setMArch - Override the architecture set by the Module's triple.
599   EngineBuilder &setMArch(StringRef march) {
600     MArch.assign(march.begin(), march.end());
601     return *this;
602   }
603
604   /// setMCPU - Target a specific cpu type.
605   EngineBuilder &setMCPU(StringRef mcpu) {
606     MCPU.assign(mcpu.begin(), mcpu.end());
607     return *this;
608   }
609
610   /// setVerifyModules - Set whether the JIT implementation should verify
611   /// IR modules during compilation.
612   EngineBuilder &setVerifyModules(bool Verify) {
613     VerifyModules = Verify;
614     return *this;
615   }
616
617   /// setMAttrs - Set cpu-specific attributes.
618   template<typename StringSequence>
619   EngineBuilder &setMAttrs(const StringSequence &mattrs) {
620     MAttrs.clear();
621     MAttrs.append(mattrs.begin(), mattrs.end());
622     return *this;
623   }
624
625   TargetMachine *selectTarget();
626
627   /// selectTarget - Pick a target either via -march or by guessing the native
628   /// arch.  Add any CPU features specified via -mcpu or -mattr.
629   TargetMachine *selectTarget(const Triple &TargetTriple,
630                               StringRef MArch,
631                               StringRef MCPU,
632                               const SmallVectorImpl<std::string>& MAttrs);
633
634   ExecutionEngine *create() {
635     return create(selectTarget());
636   }
637
638   ExecutionEngine *create(TargetMachine *TM);
639 };
640
641 // Create wrappers for C Binding types (see CBindingWrapping.h).
642 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
643
644 } // End llvm namespace
645
646 #endif