• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/MC/MCCodeGenInfo.h"
26 #include "llvm/Object/Binary.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/Mutex.h"
29 #include "llvm/Target/TargetMachine.h"
30 #include "llvm/Target/TargetOptions.h"
31 #include <map>
32 #include <string>
33 #include <vector>
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 
getGlobalAddressMap()78   GlobalAddressMapTy &getGlobalAddressMap() {
79     return GlobalAddressMap;
80   }
81 
getGlobalAddressReverseMap()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 /// \brief Abstract interface for implementation execution of LLVM modules,
93 /// designed to support both interpreter and just-in-time (JIT) compiler
94 /// implementations.
95 class ExecutionEngine {
96   /// The state object holding the global address mapping, which must be
97   /// accessed synchronously.
98   //
99   // FIXME: There is no particular need the entire map needs to be
100   // synchronized.  Wouldn't a reader-writer design be better here?
101   ExecutionEngineState EEState;
102 
103   /// The target data for the platform for which execution is being performed.
104   const DataLayout *DL;
105 
106   /// Whether lazy JIT compilation is enabled.
107   bool CompilingLazily;
108 
109   /// Whether JIT compilation of external global variables is allowed.
110   bool GVCompilationDisabled;
111 
112   /// Whether the JIT should perform lookups of external symbols (e.g.,
113   /// using dlsym).
114   bool SymbolSearchingDisabled;
115 
116   /// Whether the JIT should verify IR modules during compilation.
117   bool VerifyModules;
118 
119   friend class EngineBuilder;  // To allow access to JITCtor and InterpCtor.
120 
121 protected:
122   /// The list of Modules that we are JIT'ing from.  We use a SmallVector to
123   /// optimize for the case where there is only one module.
124   SmallVector<std::unique_ptr<Module>, 1> Modules;
125 
setDataLayout(const DataLayout * Val)126   void setDataLayout(const DataLayout *Val) { DL = Val; }
127 
128   /// getMemoryforGV - Allocate memory for a global variable.
129   virtual char *getMemoryForGV(const GlobalVariable *GV);
130 
131   static ExecutionEngine *(*MCJITCtor)(
132                                 std::unique_ptr<Module> M,
133                                 std::string *ErrorStr,
134                                 std::shared_ptr<MCJITMemoryManager> MM,
135                                 std::shared_ptr<RuntimeDyld::SymbolResolver> SR,
136                                 std::unique_ptr<TargetMachine> TM);
137 
138   static ExecutionEngine *(*OrcMCJITReplacementCtor)(
139                                 std::string *ErrorStr,
140                                 std::shared_ptr<MCJITMemoryManager> MM,
141                                 std::shared_ptr<RuntimeDyld::SymbolResolver> SR,
142                                 std::unique_ptr<TargetMachine> TM);
143 
144   static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M,
145                                         std::string *ErrorStr);
146 
147   /// LazyFunctionCreator - If an unknown function is needed, this function
148   /// pointer is invoked to create it.  If this returns null, the JIT will
149   /// abort.
150   void *(*LazyFunctionCreator)(const std::string &);
151 
152   /// getMangledName - Get mangled name.
153   std::string getMangledName(const GlobalValue *GV);
154 
155 public:
156   /// lock - This lock protects the ExecutionEngine and MCJIT classes. It must
157   /// be held while changing the internal state of 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.
addModule(std::unique_ptr<Module> M)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 
getDataLayout()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   virtual void *getPointerToNamedFunction(StringRef Name,
220                                           bool AbortOnFailure = true) = 0;
221 
222   /// mapSectionAddress - map a section to its target address space value.
223   /// Map the address of a JIT section as returned from the memory manager
224   /// to the address in the target process as the running code will see it.
225   /// This is the address which will be used for relocation resolution.
mapSectionAddress(const void * LocalAddress,uint64_t TargetAddress)226   virtual void mapSectionAddress(const void *LocalAddress,
227                                  uint64_t TargetAddress) {
228     llvm_unreachable("Re-mapping of section addresses not supported with this "
229                      "EE!");
230   }
231 
232   /// generateCodeForModule - Run code generation for the specified module and
233   /// load it into memory.
234   ///
235   /// When this function has completed, all code and data for the specified
236   /// module, and any module on which this module depends, will be generated
237   /// and loaded into memory, but relocations will not yet have been applied
238   /// and all memory will be readable and writable but not executable.
239   ///
240   /// This function is primarily useful when generating code for an external
241   /// target, allowing the client an opportunity to remap section addresses
242   /// before relocations are applied.  Clients that intend to execute code
243   /// locally can use the getFunctionAddress call, which will generate code
244   /// and apply final preparations all in one step.
245   ///
246   /// This method has no effect for the interpeter.
generateCodeForModule(Module * M)247   virtual void generateCodeForModule(Module *M) {}
248 
249   /// finalizeObject - ensure the module is fully processed and is usable.
250   ///
251   /// It is the user-level function for completing the process of making the
252   /// object usable for execution.  It should be called after sections within an
253   /// object have been relocated using mapSectionAddress.  When this method is
254   /// called the MCJIT execution engine will reapply relocations for a loaded
255   /// object.  This method has no effect for the interpeter.
finalizeObject()256   virtual void finalizeObject() {}
257 
258   /// runStaticConstructorsDestructors - This method is used to execute all of
259   /// the static constructors or destructors for a program.
260   ///
261   /// \param isDtors - Run the destructors instead of constructors.
262   virtual void runStaticConstructorsDestructors(bool isDtors);
263 
264   /// This method is used to execute all of the static constructors or
265   /// destructors for a particular module.
266   ///
267   /// \param isDtors - Run the destructors instead of constructors.
268   void runStaticConstructorsDestructors(Module &module, bool isDtors);
269 
270 
271   /// runFunctionAsMain - This is a helper function which wraps runFunction to
272   /// handle the common task of starting up main with the specified argc, argv,
273   /// and envp parameters.
274   int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
275                         const char * const * envp);
276 
277 
278   /// addGlobalMapping - Tell the execution engine that the specified global is
279   /// at the specified location.  This is used internally as functions are JIT'd
280   /// and as global variables are laid out in memory.  It can and should also be
281   /// used by clients of the EE that want to have an LLVM global overlay
282   /// existing data in memory.  Mappings are automatically removed when their
283   /// GlobalValue is destroyed.
284   void addGlobalMapping(const GlobalValue *GV, void *Addr);
285   void addGlobalMapping(StringRef Name, uint64_t Addr);
286 
287   /// clearAllGlobalMappings - Clear all global mappings and start over again,
288   /// for use in dynamic compilation scenarios to move globals.
289   void clearAllGlobalMappings();
290 
291   /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
292   /// particular module, because it has been removed from the JIT.
293   void clearGlobalMappingsFromModule(Module *M);
294 
295   /// updateGlobalMapping - Replace an existing mapping for GV with a new
296   /// address.  This updates both maps as required.  If "Addr" is null, the
297   /// entry for the global is removed from the mappings.  This returns the old
298   /// value of the pointer, or null if it was not in the map.
299   uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr);
300   uint64_t updateGlobalMapping(StringRef Name, uint64_t Addr);
301 
302   /// getAddressToGlobalIfAvailable - This returns the address of the specified
303   /// global symbol.
304   uint64_t getAddressToGlobalIfAvailable(StringRef S);
305 
306   /// getPointerToGlobalIfAvailable - This returns the address of the specified
307   /// global value if it is has already been codegen'd, otherwise it returns
308   /// null.
309   void *getPointerToGlobalIfAvailable(StringRef S);
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.
getPointerToFunctionOrStub(Function * F)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 interpreter engine.
getGlobalValueAddress(const std::string & Name)345   virtual uint64_t getGlobalValueAddress(const std::string &Name) {
346     // Default implementation for the 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.
getFunctionAddress(const std::string & Name)353   virtual uint64_t getFunctionAddress(const std::string &Name) {
354     // Default implementation for the interpreter.  MCJIT will override this.
355     // Interpreter clients should use getPointerToFunction instead.
356     return 0;
357   }
358 
359   /// getGlobalValueAtAddress - Return the LLVM global value object that starts
360   /// at the specified address.
361   ///
362   const GlobalValue *getGlobalValueAtAddress(void *Addr);
363 
364   /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
365   /// Ptr is the address of the memory at which to store Val, cast to
366   /// GenericValue *.  It is not a pointer to a GenericValue containing the
367   /// address at which to store Val.
368   void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
369                           Type *Ty);
370 
371   void InitializeMemory(const Constant *Init, void *Addr);
372 
373   /// getOrEmitGlobalVariable - Return the address of the specified global
374   /// variable, possibly emitting it to memory if needed.  This is used by the
375   /// Emitter.
376   ///
377   /// This function is deprecated for the MCJIT execution engine.  Use
378   /// getGlobalValueAddress instead.
getOrEmitGlobalVariable(const GlobalVariable * GV)379   virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
380     return getPointerToGlobal((const GlobalValue *)GV);
381   }
382 
383   /// Registers a listener to be called back on various events within
384   /// the JIT.  See JITEventListener.h for more details.  Does not
385   /// take ownership of the argument.  The argument may be NULL, in
386   /// which case these functions do nothing.
RegisterJITEventListener(JITEventListener *)387   virtual void RegisterJITEventListener(JITEventListener *) {}
UnregisterJITEventListener(JITEventListener *)388   virtual void UnregisterJITEventListener(JITEventListener *) {}
389 
390   /// Sets the pre-compiled object cache.  The ownership of the ObjectCache is
391   /// not changed.  Supported by MCJIT but not the interpreter.
setObjectCache(ObjectCache *)392   virtual void setObjectCache(ObjectCache *) {
393     llvm_unreachable("No support for an object cache");
394   }
395 
396   /// setProcessAllSections (MCJIT Only): By default, only sections that are
397   /// "required for execution" are passed to the RTDyldMemoryManager, and other
398   /// sections are discarded. Passing 'true' to this method will cause
399   /// RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless
400   /// of whether they are "required to execute" in the usual sense.
401   ///
402   /// Rationale: Some MCJIT clients want to be able to inspect metadata
403   /// sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze
404   /// performance. Passing these sections to the memory manager allows the
405   /// client to make policy about the relevant sections, rather than having
406   /// MCJIT do it.
setProcessAllSections(bool ProcessAllSections)407   virtual void setProcessAllSections(bool ProcessAllSections) {
408     llvm_unreachable("No support for ProcessAllSections option");
409   }
410 
411   /// Return the target machine (if available).
getTargetMachine()412   virtual TargetMachine *getTargetMachine() { return nullptr; }
413 
414   /// DisableLazyCompilation - When lazy compilation is off (the default), the
415   /// JIT will eagerly compile every function reachable from the argument to
416   /// getPointerToFunction.  If lazy compilation is turned on, the JIT will only
417   /// compile the one function and emit stubs to compile the rest when they're
418   /// first called.  If lazy compilation is turned off again while some lazy
419   /// stubs are still around, and one of those stubs is called, the program will
420   /// abort.
421   ///
422   /// In order to safely compile lazily in a threaded program, the user must
423   /// ensure that 1) only one thread at a time can call any particular lazy
424   /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
425   /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
426   /// lazy stub.  See http://llvm.org/PR5184 for details.
427   void DisableLazyCompilation(bool Disabled = true) {
428     CompilingLazily = !Disabled;
429   }
isCompilingLazily()430   bool isCompilingLazily() const {
431     return CompilingLazily;
432   }
433 
434   /// DisableGVCompilation - If called, the JIT will abort if it's asked to
435   /// allocate space and populate a GlobalVariable that is not internal to
436   /// the module.
437   void DisableGVCompilation(bool Disabled = true) {
438     GVCompilationDisabled = Disabled;
439   }
isGVCompilationDisabled()440   bool isGVCompilationDisabled() const {
441     return GVCompilationDisabled;
442   }
443 
444   /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
445   /// symbols with dlsym.  A client can still use InstallLazyFunctionCreator to
446   /// resolve symbols in a custom way.
447   void DisableSymbolSearching(bool Disabled = true) {
448     SymbolSearchingDisabled = Disabled;
449   }
isSymbolSearchingDisabled()450   bool isSymbolSearchingDisabled() const {
451     return SymbolSearchingDisabled;
452   }
453 
454   /// Enable/Disable IR module verification.
455   ///
456   /// Note: Module verification is enabled by default in Debug builds, and
457   /// disabled by default in Release. Use this method to override the default.
setVerifyModules(bool Verify)458   void setVerifyModules(bool Verify) {
459     VerifyModules = Verify;
460   }
getVerifyModules()461   bool getVerifyModules() const {
462     return VerifyModules;
463   }
464 
465   /// InstallLazyFunctionCreator - If an unknown function is needed, the
466   /// specified function pointer is invoked to create it.  If it returns null,
467   /// the JIT will abort.
InstallLazyFunctionCreator(void * (* P)(const std::string &))468   void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
469     LazyFunctionCreator = P;
470   }
471 
472 protected:
ExecutionEngine()473   ExecutionEngine() {}
474   explicit ExecutionEngine(std::unique_ptr<Module> M);
475 
476   void emitGlobals();
477 
478   void EmitGlobalVariable(const GlobalVariable *GV);
479 
480   GenericValue getConstantValue(const Constant *C);
481   void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
482                            Type *Ty);
483 };
484 
485 namespace EngineKind {
486   // These are actually bitmasks that get or-ed together.
487   enum Kind {
488     JIT         = 0x1,
489     Interpreter = 0x2
490   };
491   const static Kind Either = (Kind)(JIT | Interpreter);
492 }
493 
494 /// Builder class for ExecutionEngines. Use this by stack-allocating a builder,
495 /// chaining the various set* methods, and terminating it with a .create()
496 /// call.
497 class EngineBuilder {
498 private:
499   std::unique_ptr<Module> M;
500   EngineKind::Kind WhichEngine;
501   std::string *ErrorStr;
502   CodeGenOpt::Level OptLevel;
503   std::shared_ptr<MCJITMemoryManager> MemMgr;
504   std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver;
505   TargetOptions Options;
506   Reloc::Model RelocModel;
507   CodeModel::Model CMModel;
508   std::string MArch;
509   std::string MCPU;
510   SmallVector<std::string, 4> MAttrs;
511   bool VerifyModules;
512   bool UseOrcMCJITReplacement;
513 
514 public:
515   /// Default constructor for EngineBuilder.
516   EngineBuilder();
517 
518   /// Constructor for EngineBuilder.
519   EngineBuilder(std::unique_ptr<Module> M);
520 
521   // Out-of-line since we don't have the def'n of RTDyldMemoryManager here.
522   ~EngineBuilder();
523 
524   /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
525   /// or whichever engine works.  This option defaults to EngineKind::Either.
setEngineKind(EngineKind::Kind w)526   EngineBuilder &setEngineKind(EngineKind::Kind w) {
527     WhichEngine = w;
528     return *this;
529   }
530 
531   /// setMCJITMemoryManager - Sets the MCJIT memory manager to use. This allows
532   /// clients to customize their memory allocation policies for the MCJIT. This
533   /// is only appropriate for the MCJIT; setting this and configuring the builder
534   /// to create anything other than MCJIT will cause a runtime error. If create()
535   /// is called and is successful, the created engine takes ownership of the
536   /// memory manager. This option defaults to NULL.
537   EngineBuilder &setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
538 
539   EngineBuilder&
540   setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
541 
542   EngineBuilder&
543   setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
544 
545   /// setErrorStr - Set the error string to write to on error.  This option
546   /// defaults to NULL.
setErrorStr(std::string * e)547   EngineBuilder &setErrorStr(std::string *e) {
548     ErrorStr = e;
549     return *this;
550   }
551 
552   /// setOptLevel - Set the optimization level for the JIT.  This option
553   /// defaults to CodeGenOpt::Default.
setOptLevel(CodeGenOpt::Level l)554   EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
555     OptLevel = l;
556     return *this;
557   }
558 
559   /// setTargetOptions - Set the target options that the ExecutionEngine
560   /// target is using. Defaults to TargetOptions().
setTargetOptions(const TargetOptions & Opts)561   EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
562     Options = Opts;
563     return *this;
564   }
565 
566   /// setRelocationModel - Set the relocation model that the ExecutionEngine
567   /// target is using. Defaults to target specific default "Reloc::Default".
setRelocationModel(Reloc::Model RM)568   EngineBuilder &setRelocationModel(Reloc::Model RM) {
569     RelocModel = RM;
570     return *this;
571   }
572 
573   /// setCodeModel - Set the CodeModel that the ExecutionEngine target
574   /// data is using. Defaults to target specific default
575   /// "CodeModel::JITDefault".
setCodeModel(CodeModel::Model M)576   EngineBuilder &setCodeModel(CodeModel::Model M) {
577     CMModel = M;
578     return *this;
579   }
580 
581   /// setMArch - Override the architecture set by the Module's triple.
setMArch(StringRef march)582   EngineBuilder &setMArch(StringRef march) {
583     MArch.assign(march.begin(), march.end());
584     return *this;
585   }
586 
587   /// setMCPU - Target a specific cpu type.
setMCPU(StringRef mcpu)588   EngineBuilder &setMCPU(StringRef mcpu) {
589     MCPU.assign(mcpu.begin(), mcpu.end());
590     return *this;
591   }
592 
593   /// setVerifyModules - Set whether the JIT implementation should verify
594   /// IR modules during compilation.
setVerifyModules(bool Verify)595   EngineBuilder &setVerifyModules(bool Verify) {
596     VerifyModules = Verify;
597     return *this;
598   }
599 
600   /// setMAttrs - Set cpu-specific attributes.
601   template<typename StringSequence>
setMAttrs(const StringSequence & mattrs)602   EngineBuilder &setMAttrs(const StringSequence &mattrs) {
603     MAttrs.clear();
604     MAttrs.append(mattrs.begin(), mattrs.end());
605     return *this;
606   }
607 
608   // \brief Use OrcMCJITReplacement instead of MCJIT. Off by default.
setUseOrcMCJITReplacement(bool UseOrcMCJITReplacement)609   void setUseOrcMCJITReplacement(bool UseOrcMCJITReplacement) {
610     this->UseOrcMCJITReplacement = UseOrcMCJITReplacement;
611   }
612 
613   TargetMachine *selectTarget();
614 
615   /// selectTarget - Pick a target either via -march or by guessing the native
616   /// arch.  Add any CPU features specified via -mcpu or -mattr.
617   TargetMachine *selectTarget(const Triple &TargetTriple,
618                               StringRef MArch,
619                               StringRef MCPU,
620                               const SmallVectorImpl<std::string>& MAttrs);
621 
create()622   ExecutionEngine *create() {
623     return create(selectTarget());
624   }
625 
626   ExecutionEngine *create(TargetMachine *TM);
627 };
628 
629 // Create wrappers for C Binding types (see CBindingWrapping.h).
630 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
631 
632 } // End llvm namespace
633 
634 #endif
635