OSDN Git Service

f68337c43271893dca1f9cbc2f667794f9925071
[android-x86/external-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 "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<JITSymbolResolver> 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<JITSymbolResolver> 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 - Removes a Module from the list of modules, but does not
202   /// free the module's memory. Returns true if M is found, in which case the
203   /// caller assumes responsibility for deleting the module.
204   //
205   // FIXME: This stealth ownership transfer is horrible. This will probably be
206   //        fixed by deleting ExecutionEngine.
207   virtual bool removeModule(Module *M);
208
209   /// FindFunctionNamed - Search all of the active modules to find the function that
210   /// defines FnName.  This is very slow operation and shouldn't be used for
211   /// general code.
212   virtual Function *FindFunctionNamed(StringRef FnName);
213
214   /// FindGlobalVariableNamed - Search all of the active modules to find the global variable
215   /// that defines Name.  This is very slow operation and shouldn't be used for
216   /// general code.
217   virtual GlobalVariable *FindGlobalVariableNamed(StringRef Name, bool AllowInternal = false);
218
219   /// runFunction - Execute the specified function with the specified arguments,
220   /// and return the result.
221   ///
222   /// For MCJIT execution engines, clients are encouraged to use the
223   /// "GetFunctionAddress" method (rather than runFunction) and cast the
224   /// returned uint64_t to the desired function pointer type. However, for
225   /// backwards compatibility MCJIT's implementation can execute 'main-like'
226   /// function (i.e. those returning void or int, and taking either no
227   /// arguments or (int, char*[])).
228   virtual GenericValue runFunction(Function *F,
229                                    ArrayRef<GenericValue> ArgValues) = 0;
230
231   /// getPointerToNamedFunction - This method returns the address of the
232   /// specified function by using the dlsym function call.  As such it is only
233   /// useful for resolving library symbols, not code generated symbols.
234   ///
235   /// If AbortOnFailure is false and no function with the given name is
236   /// found, this function silently returns a null pointer. Otherwise,
237   /// it prints a message to stderr and aborts.
238   ///
239   /// This function is deprecated for the MCJIT execution engine.
240   virtual void *getPointerToNamedFunction(StringRef Name,
241                                           bool AbortOnFailure = true) = 0;
242
243   /// mapSectionAddress - map a section to its target address space value.
244   /// Map the address of a JIT section as returned from the memory manager
245   /// to the address in the target process as the running code will see it.
246   /// This is the address which will be used for relocation resolution.
247   virtual void mapSectionAddress(const void *LocalAddress,
248                                  uint64_t TargetAddress) {
249     llvm_unreachable("Re-mapping of section addresses not supported with this "
250                      "EE!");
251   }
252
253   /// generateCodeForModule - Run code generation for the specified module and
254   /// load it into memory.
255   ///
256   /// When this function has completed, all code and data for the specified
257   /// module, and any module on which this module depends, will be generated
258   /// and loaded into memory, but relocations will not yet have been applied
259   /// and all memory will be readable and writable but not executable.
260   ///
261   /// This function is primarily useful when generating code for an external
262   /// target, allowing the client an opportunity to remap section addresses
263   /// before relocations are applied.  Clients that intend to execute code
264   /// locally can use the getFunctionAddress call, which will generate code
265   /// and apply final preparations all in one step.
266   ///
267   /// This method has no effect for the interpeter.
268   virtual void generateCodeForModule(Module *M) {}
269
270   /// finalizeObject - ensure the module is fully processed and is usable.
271   ///
272   /// It is the user-level function for completing the process of making the
273   /// object usable for execution.  It should be called after sections within an
274   /// object have been relocated using mapSectionAddress.  When this method is
275   /// called the MCJIT execution engine will reapply relocations for a loaded
276   /// object.  This method has no effect for the interpeter.
277   virtual void finalizeObject() {}
278
279   /// runStaticConstructorsDestructors - This method is used to execute all of
280   /// the static constructors or destructors for a program.
281   ///
282   /// \param isDtors - Run the destructors instead of constructors.
283   virtual void runStaticConstructorsDestructors(bool isDtors);
284
285   /// This method is used to execute all of the static constructors or
286   /// destructors for a particular module.
287   ///
288   /// \param isDtors - Run the destructors instead of constructors.
289   void runStaticConstructorsDestructors(Module &module, bool isDtors);
290
291
292   /// runFunctionAsMain - This is a helper function which wraps runFunction to
293   /// handle the common task of starting up main with the specified argc, argv,
294   /// and envp parameters.
295   int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
296                         const char * const * envp);
297
298
299   /// addGlobalMapping - Tell the execution engine that the specified global is
300   /// at the specified location.  This is used internally as functions are JIT'd
301   /// and as global variables are laid out in memory.  It can and should also be
302   /// used by clients of the EE that want to have an LLVM global overlay
303   /// existing data in memory. Values to be mapped should be named, and have
304   /// external or weak linkage. Mappings are automatically removed when their
305   /// GlobalValue is destroyed.
306   void addGlobalMapping(const GlobalValue *GV, void *Addr);
307   void addGlobalMapping(StringRef Name, uint64_t Addr);
308
309   /// clearAllGlobalMappings - Clear all global mappings and start over again,
310   /// for use in dynamic compilation scenarios to move globals.
311   void clearAllGlobalMappings();
312
313   /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
314   /// particular module, because it has been removed from the JIT.
315   void clearGlobalMappingsFromModule(Module *M);
316
317   /// updateGlobalMapping - Replace an existing mapping for GV with a new
318   /// address.  This updates both maps as required.  If "Addr" is null, the
319   /// entry for the global is removed from the mappings.  This returns the old
320   /// value of the pointer, or null if it was not in the map.
321   uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr);
322   uint64_t updateGlobalMapping(StringRef Name, uint64_t Addr);
323
324   /// getAddressToGlobalIfAvailable - This returns the address of the specified
325   /// global symbol.
326   uint64_t getAddressToGlobalIfAvailable(StringRef S);
327
328   /// getPointerToGlobalIfAvailable - This returns the address of the specified
329   /// global value if it is has already been codegen'd, otherwise it returns
330   /// null.
331   void *getPointerToGlobalIfAvailable(StringRef S);
332   void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
333
334   /// getPointerToGlobal - This returns the address of the specified global
335   /// value. This may involve code generation if it's a function.
336   ///
337   /// This function is deprecated for the MCJIT execution engine.  Use
338   /// getGlobalValueAddress instead.
339   void *getPointerToGlobal(const GlobalValue *GV);
340
341   /// getPointerToFunction - The different EE's represent function bodies in
342   /// different ways.  They should each implement this to say what a function
343   /// pointer should look like.  When F is destroyed, the ExecutionEngine will
344   /// remove its global mapping and free any machine code.  Be sure no threads
345   /// are running inside F when that happens.
346   ///
347   /// This function is deprecated for the MCJIT execution engine.  Use
348   /// getFunctionAddress instead.
349   virtual void *getPointerToFunction(Function *F) = 0;
350
351   /// getPointerToFunctionOrStub - If the specified function has been
352   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
353   /// a stub to implement lazy compilation if available.  See
354   /// getPointerToFunction for the requirements on destroying F.
355   ///
356   /// This function is deprecated for the MCJIT execution engine.  Use
357   /// getFunctionAddress instead.
358   virtual void *getPointerToFunctionOrStub(Function *F) {
359     // Default implementation, just codegen the function.
360     return getPointerToFunction(F);
361   }
362
363   /// getGlobalValueAddress - Return the address of the specified global
364   /// value. This may involve code generation.
365   ///
366   /// This function should not be called with the interpreter engine.
367   virtual uint64_t getGlobalValueAddress(const std::string &Name) {
368     // Default implementation for the interpreter.  MCJIT will override this.
369     // JIT and interpreter clients should use getPointerToGlobal instead.
370     return 0;
371   }
372
373   /// getFunctionAddress - Return the address of the specified function.
374   /// This may involve code generation.
375   virtual uint64_t getFunctionAddress(const std::string &Name) {
376     // Default implementation for the interpreter.  MCJIT will override this.
377     // Interpreter clients should use getPointerToFunction instead.
378     return 0;
379   }
380
381   /// getGlobalValueAtAddress - Return the LLVM global value object that starts
382   /// at the specified address.
383   ///
384   const GlobalValue *getGlobalValueAtAddress(void *Addr);
385
386   /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
387   /// Ptr is the address of the memory at which to store Val, cast to
388   /// GenericValue *.  It is not a pointer to a GenericValue containing the
389   /// address at which to store Val.
390   void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
391                           Type *Ty);
392
393   void InitializeMemory(const Constant *Init, void *Addr);
394
395   /// getOrEmitGlobalVariable - Return the address of the specified global
396   /// variable, possibly emitting it to memory if needed.  This is used by the
397   /// Emitter.
398   ///
399   /// This function is deprecated for the MCJIT execution engine.  Use
400   /// getGlobalValueAddress instead.
401   virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
402     return getPointerToGlobal((const GlobalValue *)GV);
403   }
404
405   /// Registers a listener to be called back on various events within
406   /// the JIT.  See JITEventListener.h for more details.  Does not
407   /// take ownership of the argument.  The argument may be NULL, in
408   /// which case these functions do nothing.
409   virtual void RegisterJITEventListener(JITEventListener *) {}
410   virtual void UnregisterJITEventListener(JITEventListener *) {}
411
412   /// Sets the pre-compiled object cache.  The ownership of the ObjectCache is
413   /// not changed.  Supported by MCJIT but not the interpreter.
414   virtual void setObjectCache(ObjectCache *) {
415     llvm_unreachable("No support for an object cache");
416   }
417
418   /// setProcessAllSections (MCJIT Only): By default, only sections that are
419   /// "required for execution" are passed to the RTDyldMemoryManager, and other
420   /// sections are discarded. Passing 'true' to this method will cause
421   /// RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless
422   /// of whether they are "required to execute" in the usual sense.
423   ///
424   /// Rationale: Some MCJIT clients want to be able to inspect metadata
425   /// sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze
426   /// performance. Passing these sections to the memory manager allows the
427   /// client to make policy about the relevant sections, rather than having
428   /// MCJIT do it.
429   virtual void setProcessAllSections(bool ProcessAllSections) {
430     llvm_unreachable("No support for ProcessAllSections option");
431   }
432
433   /// Return the target machine (if available).
434   virtual TargetMachine *getTargetMachine() { return nullptr; }
435
436   /// DisableLazyCompilation - When lazy compilation is off (the default), the
437   /// JIT will eagerly compile every function reachable from the argument to
438   /// getPointerToFunction.  If lazy compilation is turned on, the JIT will only
439   /// compile the one function and emit stubs to compile the rest when they're
440   /// first called.  If lazy compilation is turned off again while some lazy
441   /// stubs are still around, and one of those stubs is called, the program will
442   /// abort.
443   ///
444   /// In order to safely compile lazily in a threaded program, the user must
445   /// ensure that 1) only one thread at a time can call any particular lazy
446   /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
447   /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
448   /// lazy stub.  See http://llvm.org/PR5184 for details.
449   void DisableLazyCompilation(bool Disabled = true) {
450     CompilingLazily = !Disabled;
451   }
452   bool isCompilingLazily() const {
453     return CompilingLazily;
454   }
455
456   /// DisableGVCompilation - If called, the JIT will abort if it's asked to
457   /// allocate space and populate a GlobalVariable that is not internal to
458   /// the module.
459   void DisableGVCompilation(bool Disabled = true) {
460     GVCompilationDisabled = Disabled;
461   }
462   bool isGVCompilationDisabled() const {
463     return GVCompilationDisabled;
464   }
465
466   /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
467   /// symbols with dlsym.  A client can still use InstallLazyFunctionCreator to
468   /// resolve symbols in a custom way.
469   void DisableSymbolSearching(bool Disabled = true) {
470     SymbolSearchingDisabled = Disabled;
471   }
472   bool isSymbolSearchingDisabled() const {
473     return SymbolSearchingDisabled;
474   }
475
476   /// Enable/Disable IR module verification.
477   ///
478   /// Note: Module verification is enabled by default in Debug builds, and
479   /// disabled by default in Release. Use this method to override the default.
480   void setVerifyModules(bool Verify) {
481     VerifyModules = Verify;
482   }
483   bool getVerifyModules() const {
484     return VerifyModules;
485   }
486
487   /// InstallLazyFunctionCreator - If an unknown function is needed, the
488   /// specified function pointer is invoked to create it.  If it returns null,
489   /// the JIT will abort.
490   void InstallLazyFunctionCreator(FunctionCreator C) {
491     LazyFunctionCreator = std::move(C);
492   }
493
494 protected:
495   ExecutionEngine(DataLayout DL) : DL(std::move(DL)) {}
496   explicit ExecutionEngine(DataLayout DL, std::unique_ptr<Module> M);
497   explicit ExecutionEngine(std::unique_ptr<Module> M);
498
499   void emitGlobals();
500
501   void EmitGlobalVariable(const GlobalVariable *GV);
502
503   GenericValue getConstantValue(const Constant *C);
504   void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
505                            Type *Ty);
506
507 private:
508   void Init(std::unique_ptr<Module> M);
509 };
510
511 namespace EngineKind {
512   // These are actually bitmasks that get or-ed together.
513   enum Kind {
514     JIT         = 0x1,
515     Interpreter = 0x2
516   };
517   const static Kind Either = (Kind)(JIT | Interpreter);
518 }
519
520 /// Builder class for ExecutionEngines. Use this by stack-allocating a builder,
521 /// chaining the various set* methods, and terminating it with a .create()
522 /// call.
523 class EngineBuilder {
524 private:
525   std::unique_ptr<Module> M;
526   EngineKind::Kind WhichEngine;
527   std::string *ErrorStr;
528   CodeGenOpt::Level OptLevel;
529   std::shared_ptr<MCJITMemoryManager> MemMgr;
530   std::shared_ptr<JITSymbolResolver> Resolver;
531   TargetOptions Options;
532   Optional<Reloc::Model> RelocModel;
533   CodeModel::Model CMModel;
534   std::string MArch;
535   std::string MCPU;
536   SmallVector<std::string, 4> MAttrs;
537   bool VerifyModules;
538   bool UseOrcMCJITReplacement;
539
540 public:
541   /// Default constructor for EngineBuilder.
542   EngineBuilder();
543
544   /// Constructor for EngineBuilder.
545   EngineBuilder(std::unique_ptr<Module> M);
546
547   // Out-of-line since we don't have the def'n of RTDyldMemoryManager here.
548   ~EngineBuilder();
549
550   /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
551   /// or whichever engine works.  This option defaults to EngineKind::Either.
552   EngineBuilder &setEngineKind(EngineKind::Kind w) {
553     WhichEngine = w;
554     return *this;
555   }
556
557   /// setMCJITMemoryManager - Sets the MCJIT memory manager to use. This allows
558   /// clients to customize their memory allocation policies for the MCJIT. This
559   /// is only appropriate for the MCJIT; setting this and configuring the builder
560   /// to create anything other than MCJIT will cause a runtime error. If create()
561   /// is called and is successful, the created engine takes ownership of the
562   /// memory manager. This option defaults to NULL.
563   EngineBuilder &setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
564
565   EngineBuilder&
566   setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
567
568   EngineBuilder&
569   setSymbolResolver(std::unique_ptr<JITSymbolResolver> SR);
570
571   /// setErrorStr - Set the error string to write to on error.  This option
572   /// defaults to NULL.
573   EngineBuilder &setErrorStr(std::string *e) {
574     ErrorStr = e;
575     return *this;
576   }
577
578   /// setOptLevel - Set the optimization level for the JIT.  This option
579   /// defaults to CodeGenOpt::Default.
580   EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
581     OptLevel = l;
582     return *this;
583   }
584
585   /// setTargetOptions - Set the target options that the ExecutionEngine
586   /// target is using. Defaults to TargetOptions().
587   EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
588     Options = Opts;
589     return *this;
590   }
591
592   /// setRelocationModel - Set the relocation model that the ExecutionEngine
593   /// target is using. Defaults to target specific default "Reloc::Default".
594   EngineBuilder &setRelocationModel(Reloc::Model RM) {
595     RelocModel = RM;
596     return *this;
597   }
598
599   /// setCodeModel - Set the CodeModel that the ExecutionEngine target
600   /// data is using. Defaults to target specific default
601   /// "CodeModel::JITDefault".
602   EngineBuilder &setCodeModel(CodeModel::Model M) {
603     CMModel = M;
604     return *this;
605   }
606
607   /// setMArch - Override the architecture set by the Module's triple.
608   EngineBuilder &setMArch(StringRef march) {
609     MArch.assign(march.begin(), march.end());
610     return *this;
611   }
612
613   /// setMCPU - Target a specific cpu type.
614   EngineBuilder &setMCPU(StringRef mcpu) {
615     MCPU.assign(mcpu.begin(), mcpu.end());
616     return *this;
617   }
618
619   /// setVerifyModules - Set whether the JIT implementation should verify
620   /// IR modules during compilation.
621   EngineBuilder &setVerifyModules(bool Verify) {
622     VerifyModules = Verify;
623     return *this;
624   }
625
626   /// setMAttrs - Set cpu-specific attributes.
627   template<typename StringSequence>
628   EngineBuilder &setMAttrs(const StringSequence &mattrs) {
629     MAttrs.clear();
630     MAttrs.append(mattrs.begin(), mattrs.end());
631     return *this;
632   }
633
634   // \brief Use OrcMCJITReplacement instead of MCJIT. Off by default.
635   void setUseOrcMCJITReplacement(bool UseOrcMCJITReplacement) {
636     this->UseOrcMCJITReplacement = UseOrcMCJITReplacement;
637   }
638
639   TargetMachine *selectTarget();
640
641   /// selectTarget - Pick a target either via -march or by guessing the native
642   /// arch.  Add any CPU features specified via -mcpu or -mattr.
643   TargetMachine *selectTarget(const Triple &TargetTriple,
644                               StringRef MArch,
645                               StringRef MCPU,
646                               const SmallVectorImpl<std::string>& MAttrs);
647
648   ExecutionEngine *create() {
649     return create(selectTarget());
650   }
651
652   ExecutionEngine *create(TargetMachine *TM);
653 };
654
655 // Create wrappers for C Binding types (see CBindingWrapping.h).
656 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef)
657
658 } // End llvm namespace
659
660 #endif