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