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