Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

630 lines
24 KiB

  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. #ifndef LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
  15. #define LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/ADT/SmallVector.h"
  18. #include "llvm/ADT/StringRef.h"
  19. #include "llvm/ADT/ValueMap.h"
  20. #include "llvm/MC/MCCodeGenInfo.h"
  21. #include "llvm/Support/ErrorHandling.h"
  22. #include "llvm/Support/Mutex.h"
  23. #include "llvm/Support/ValueHandle.h"
  24. #include "llvm/Target/TargetMachine.h"
  25. #include "llvm/Target/TargetOptions.h"
  26. #include <map>
  27. #include <string>
  28. #include <vector>
  29. namespace llvm {
  30. struct GenericValue;
  31. class Constant;
  32. class ExecutionEngine;
  33. class Function;
  34. class GlobalVariable;
  35. class GlobalValue;
  36. class JITEventListener;
  37. class JITMemoryManager;
  38. class MachineCodeInfo;
  39. class Module;
  40. class MutexGuard;
  41. class DataLayout;
  42. class Triple;
  43. class Type;
  44. /// \brief Helper class for helping synchronize access to the global address map
  45. /// table.
  46. class ExecutionEngineState {
  47. public:
  48. struct AddressMapConfig : public ValueMapConfig<const GlobalValue*> {
  49. typedef ExecutionEngineState *ExtraData;
  50. static sys::Mutex *getMutex(ExecutionEngineState *EES);
  51. static void onDelete(ExecutionEngineState *EES, const GlobalValue *Old);
  52. static void onRAUW(ExecutionEngineState *, const GlobalValue *,
  53. const GlobalValue *);
  54. };
  55. typedef ValueMap<const GlobalValue *, void *, AddressMapConfig>
  56. GlobalAddressMapTy;
  57. private:
  58. ExecutionEngine &EE;
  59. /// GlobalAddressMap - A mapping between LLVM global values and their
  60. /// actualized version...
  61. GlobalAddressMapTy GlobalAddressMap;
  62. /// GlobalAddressReverseMap - This is the reverse mapping of GlobalAddressMap,
  63. /// used to convert raw addresses into the LLVM global value that is emitted
  64. /// at the address. This map is not computed unless getGlobalValueAtAddress
  65. /// is called at some point.
  66. std::map<void *, AssertingVH<const GlobalValue> > GlobalAddressReverseMap;
  67. public:
  68. ExecutionEngineState(ExecutionEngine &EE);
  69. GlobalAddressMapTy &getGlobalAddressMap(const MutexGuard &) {
  70. return GlobalAddressMap;
  71. }
  72. std::map<void*, AssertingVH<const GlobalValue> > &
  73. getGlobalAddressReverseMap(const MutexGuard &) {
  74. return GlobalAddressReverseMap;
  75. }
  76. /// \brief Erase an entry from the mapping table.
  77. ///
  78. /// \returns The address that \p ToUnmap was happed to.
  79. void *RemoveMapping(const MutexGuard &, const GlobalValue *ToUnmap);
  80. };
  81. /// \brief Abstract interface for implementation execution of LLVM modules,
  82. /// designed to support both interpreter and just-in-time (JIT) compiler
  83. /// implementations.
  84. class ExecutionEngine {
  85. /// The state object holding the global address mapping, which must be
  86. /// accessed synchronously.
  87. //
  88. // FIXME: There is no particular need the entire map needs to be
  89. // synchronized. Wouldn't a reader-writer design be better here?
  90. ExecutionEngineState EEState;
  91. /// The target data for the platform for which execution is being performed.
  92. const DataLayout *TD;
  93. /// Whether lazy JIT compilation is enabled.
  94. bool CompilingLazily;
  95. /// Whether JIT compilation of external global variables is allowed.
  96. bool GVCompilationDisabled;
  97. /// Whether the JIT should perform lookups of external symbols (e.g.,
  98. /// using dlsym).
  99. bool SymbolSearchingDisabled;
  100. friend class EngineBuilder; // To allow access to JITCtor and InterpCtor.
  101. protected:
  102. /// The list of Modules that we are JIT'ing from. We use a SmallVector to
  103. /// optimize for the case where there is only one module.
  104. SmallVector<Module*, 1> Modules;
  105. void setDataLayout(const DataLayout *td) { TD = td; }
  106. /// getMemoryforGV - Allocate memory for a global variable.
  107. virtual char *getMemoryForGV(const GlobalVariable *GV);
  108. // To avoid having libexecutionengine depend on the JIT and interpreter
  109. // libraries, the execution engine implementations set these functions to ctor
  110. // pointers at startup time if they are linked in.
  111. static ExecutionEngine *(*JITCtor)(
  112. Module *M,
  113. std::string *ErrorStr,
  114. JITMemoryManager *JMM,
  115. bool GVsWithCode,
  116. TargetMachine *TM);
  117. static ExecutionEngine *(*MCJITCtor)(
  118. Module *M,
  119. std::string *ErrorStr,
  120. JITMemoryManager *JMM,
  121. bool GVsWithCode,
  122. TargetMachine *TM);
  123. static ExecutionEngine *(*InterpCtor)(Module *M, std::string *ErrorStr);
  124. /// LazyFunctionCreator - If an unknown function is needed, this function
  125. /// pointer is invoked to create it. If this returns null, the JIT will
  126. /// abort.
  127. void *(*LazyFunctionCreator)(const std::string &);
  128. /// ExceptionTableRegister - If Exception Handling is set, the JIT will
  129. /// register dwarf tables with this function.
  130. typedef void (*EERegisterFn)(void*);
  131. EERegisterFn ExceptionTableRegister;
  132. EERegisterFn ExceptionTableDeregister;
  133. /// This maps functions to their exception tables frames.
  134. DenseMap<const Function*, void*> AllExceptionTables;
  135. public:
  136. /// lock - This lock protects the ExecutionEngine, JIT, JITResolver and
  137. /// JITEmitter classes. It must be held while changing the internal state of
  138. /// any of those classes.
  139. sys::Mutex lock;
  140. //===--------------------------------------------------------------------===//
  141. // ExecutionEngine Startup
  142. //===--------------------------------------------------------------------===//
  143. virtual ~ExecutionEngine();
  144. /// create - This is the factory method for creating an execution engine which
  145. /// is appropriate for the current machine. This takes ownership of the
  146. /// module.
  147. ///
  148. /// \param GVsWithCode - Allocating globals with code breaks
  149. /// freeMachineCodeForFunction and is probably unsafe and bad for performance.
  150. /// However, we have clients who depend on this behavior, so we must support
  151. /// it. Eventually, when we're willing to break some backwards compatibility,
  152. /// this flag should be flipped to false, so that by default
  153. /// freeMachineCodeForFunction works.
  154. static ExecutionEngine *create(Module *M,
  155. bool ForceInterpreter = false,
  156. std::string *ErrorStr = 0,
  157. CodeGenOpt::Level OptLevel =
  158. CodeGenOpt::Default,
  159. bool GVsWithCode = true);
  160. /// createJIT - This is the factory method for creating a JIT for the current
  161. /// machine, it does not fall back to the interpreter. This takes ownership
  162. /// of the Module and JITMemoryManager if successful.
  163. ///
  164. /// Clients should make sure to initialize targets prior to calling this
  165. /// function.
  166. static ExecutionEngine *createJIT(Module *M,
  167. std::string *ErrorStr = 0,
  168. JITMemoryManager *JMM = 0,
  169. CodeGenOpt::Level OptLevel =
  170. CodeGenOpt::Default,
  171. bool GVsWithCode = true,
  172. Reloc::Model RM = Reloc::Default,
  173. CodeModel::Model CMM =
  174. CodeModel::JITDefault);
  175. /// addModule - Add a Module to the list of modules that we can JIT from.
  176. /// Note that this takes ownership of the Module: when the ExecutionEngine is
  177. /// destroyed, it destroys the Module as well.
  178. virtual void addModule(Module *M) {
  179. Modules.push_back(M);
  180. }
  181. //===--------------------------------------------------------------------===//
  182. const DataLayout *getDataLayout() const { return TD; }
  183. /// removeModule - Remove a Module from the list of modules. Returns true if
  184. /// M is found.
  185. virtual bool removeModule(Module *M);
  186. /// FindFunctionNamed - Search all of the active modules to find the one that
  187. /// defines FnName. This is very slow operation and shouldn't be used for
  188. /// general code.
  189. Function *FindFunctionNamed(const char *FnName);
  190. /// runFunction - Execute the specified function with the specified arguments,
  191. /// and return the result.
  192. virtual GenericValue runFunction(Function *F,
  193. const std::vector<GenericValue> &ArgValues) = 0;
  194. /// getPointerToNamedFunction - This method returns the address of the
  195. /// specified function by using the dlsym function call. As such it is only
  196. /// useful for resolving library symbols, not code generated symbols.
  197. ///
  198. /// If AbortOnFailure is false and no function with the given name is
  199. /// found, this function silently returns a null pointer. Otherwise,
  200. /// it prints a message to stderr and aborts.
  201. ///
  202. virtual void *getPointerToNamedFunction(const std::string &Name,
  203. bool AbortOnFailure = true) = 0;
  204. /// mapSectionAddress - map a section to its target address space value.
  205. /// Map the address of a JIT section as returned from the memory manager
  206. /// to the address in the target process as the running code will see it.
  207. /// This is the address which will be used for relocation resolution.
  208. virtual void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress) {
  209. llvm_unreachable("Re-mapping of section addresses not supported with this "
  210. "EE!");
  211. }
  212. // finalizeObject - This method should be called after sections within an
  213. // object have been relocated using mapSectionAddress. When this method is
  214. // called the MCJIT execution engine will reapply relocations for a loaded
  215. // object. This method has no effect for the legacy JIT engine or the
  216. // interpeter.
  217. virtual void finalizeObject() {}
  218. /// runStaticConstructorsDestructors - This method is used to execute all of
  219. /// the static constructors or destructors for a program.
  220. ///
  221. /// \param isDtors - Run the destructors instead of constructors.
  222. void runStaticConstructorsDestructors(bool isDtors);
  223. /// runStaticConstructorsDestructors - This method is used to execute all of
  224. /// the static constructors or destructors for a particular module.
  225. ///
  226. /// \param isDtors - Run the destructors instead of constructors.
  227. void runStaticConstructorsDestructors(Module *module, bool isDtors);
  228. /// runFunctionAsMain - This is a helper function which wraps runFunction to
  229. /// handle the common task of starting up main with the specified argc, argv,
  230. /// and envp parameters.
  231. int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
  232. const char * const * envp);
  233. /// addGlobalMapping - Tell the execution engine that the specified global is
  234. /// at the specified location. This is used internally as functions are JIT'd
  235. /// and as global variables are laid out in memory. It can and should also be
  236. /// used by clients of the EE that want to have an LLVM global overlay
  237. /// existing data in memory. Mappings are automatically removed when their
  238. /// GlobalValue is destroyed.
  239. void addGlobalMapping(const GlobalValue *GV, void *Addr);
  240. /// clearAllGlobalMappings - Clear all global mappings and start over again,
  241. /// for use in dynamic compilation scenarios to move globals.
  242. void clearAllGlobalMappings();
  243. /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
  244. /// particular module, because it has been removed from the JIT.
  245. void clearGlobalMappingsFromModule(Module *M);
  246. /// updateGlobalMapping - Replace an existing mapping for GV with a new
  247. /// address. This updates both maps as required. If "Addr" is null, the
  248. /// entry for the global is removed from the mappings. This returns the old
  249. /// value of the pointer, or null if it was not in the map.
  250. void *updateGlobalMapping(const GlobalValue *GV, void *Addr);
  251. /// getPointerToGlobalIfAvailable - This returns the address of the specified
  252. /// global value if it is has already been codegen'd, otherwise it returns
  253. /// null.
  254. void *getPointerToGlobalIfAvailable(const GlobalValue *GV);
  255. /// getPointerToGlobal - This returns the address of the specified global
  256. /// value. This may involve code generation if it's a function.
  257. void *getPointerToGlobal(const GlobalValue *GV);
  258. /// getPointerToFunction - The different EE's represent function bodies in
  259. /// different ways. They should each implement this to say what a function
  260. /// pointer should look like. When F is destroyed, the ExecutionEngine will
  261. /// remove its global mapping and free any machine code. Be sure no threads
  262. /// are running inside F when that happens.
  263. virtual void *getPointerToFunction(Function *F) = 0;
  264. /// getPointerToBasicBlock - The different EE's represent basic blocks in
  265. /// different ways. Return the representation for a blockaddress of the
  266. /// specified block.
  267. virtual void *getPointerToBasicBlock(BasicBlock *BB) = 0;
  268. /// getPointerToFunctionOrStub - If the specified function has been
  269. /// code-gen'd, return a pointer to the function. If not, compile it, or use
  270. /// a stub to implement lazy compilation if available. See
  271. /// getPointerToFunction for the requirements on destroying F.
  272. virtual void *getPointerToFunctionOrStub(Function *F) {
  273. // Default implementation, just codegen the function.
  274. return getPointerToFunction(F);
  275. }
  276. // The JIT overrides a version that actually does this.
  277. virtual void runJITOnFunction(Function *, MachineCodeInfo * = 0) { }
  278. /// getGlobalValueAtAddress - Return the LLVM global value object that starts
  279. /// at the specified address.
  280. ///
  281. const GlobalValue *getGlobalValueAtAddress(void *Addr);
  282. /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
  283. /// Ptr is the address of the memory at which to store Val, cast to
  284. /// GenericValue *. It is not a pointer to a GenericValue containing the
  285. /// address at which to store Val.
  286. void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
  287. Type *Ty);
  288. void InitializeMemory(const Constant *Init, void *Addr);
  289. /// recompileAndRelinkFunction - This method is used to force a function which
  290. /// has already been compiled to be compiled again, possibly after it has been
  291. /// modified. Then the entry to the old copy is overwritten with a branch to
  292. /// the new copy. If there was no old copy, this acts just like
  293. /// VM::getPointerToFunction().
  294. virtual void *recompileAndRelinkFunction(Function *F) = 0;
  295. /// freeMachineCodeForFunction - Release memory in the ExecutionEngine
  296. /// corresponding to the machine code emitted to execute this function, useful
  297. /// for garbage-collecting generated code.
  298. virtual void freeMachineCodeForFunction(Function *F) = 0;
  299. /// getOrEmitGlobalVariable - Return the address of the specified global
  300. /// variable, possibly emitting it to memory if needed. This is used by the
  301. /// Emitter.
  302. virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
  303. return getPointerToGlobal((const GlobalValue *)GV);
  304. }
  305. /// Registers a listener to be called back on various events within
  306. /// the JIT. See JITEventListener.h for more details. Does not
  307. /// take ownership of the argument. The argument may be NULL, in
  308. /// which case these functions do nothing.
  309. virtual void RegisterJITEventListener(JITEventListener *) {}
  310. virtual void UnregisterJITEventListener(JITEventListener *) {}
  311. /// DisableLazyCompilation - When lazy compilation is off (the default), the
  312. /// JIT will eagerly compile every function reachable from the argument to
  313. /// getPointerToFunction. If lazy compilation is turned on, the JIT will only
  314. /// compile the one function and emit stubs to compile the rest when they're
  315. /// first called. If lazy compilation is turned off again while some lazy
  316. /// stubs are still around, and one of those stubs is called, the program will
  317. /// abort.
  318. ///
  319. /// In order to safely compile lazily in a threaded program, the user must
  320. /// ensure that 1) only one thread at a time can call any particular lazy
  321. /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
  322. /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
  323. /// lazy stub. See http://llvm.org/PR5184 for details.
  324. void DisableLazyCompilation(bool Disabled = true) {
  325. CompilingLazily = !Disabled;
  326. }
  327. bool isCompilingLazily() const {
  328. return CompilingLazily;
  329. }
  330. // Deprecated in favor of isCompilingLazily (to reduce double-negatives).
  331. // Remove this in LLVM 2.8.
  332. bool isLazyCompilationDisabled() const {
  333. return !CompilingLazily;
  334. }
  335. /// DisableGVCompilation - If called, the JIT will abort if it's asked to
  336. /// allocate space and populate a GlobalVariable that is not internal to
  337. /// the module.
  338. void DisableGVCompilation(bool Disabled = true) {
  339. GVCompilationDisabled = Disabled;
  340. }
  341. bool isGVCompilationDisabled() const {
  342. return GVCompilationDisabled;
  343. }
  344. /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
  345. /// symbols with dlsym. A client can still use InstallLazyFunctionCreator to
  346. /// resolve symbols in a custom way.
  347. void DisableSymbolSearching(bool Disabled = true) {
  348. SymbolSearchingDisabled = Disabled;
  349. }
  350. bool isSymbolSearchingDisabled() const {
  351. return SymbolSearchingDisabled;
  352. }
  353. /// InstallLazyFunctionCreator - If an unknown function is needed, the
  354. /// specified function pointer is invoked to create it. If it returns null,
  355. /// the JIT will abort.
  356. void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
  357. LazyFunctionCreator = P;
  358. }
  359. /// InstallExceptionTableRegister - The JIT will use the given function
  360. /// to register the exception tables it generates.
  361. void InstallExceptionTableRegister(EERegisterFn F) {
  362. ExceptionTableRegister = F;
  363. }
  364. void InstallExceptionTableDeregister(EERegisterFn F) {
  365. ExceptionTableDeregister = F;
  366. }
  367. /// RegisterTable - Registers the given pointer as an exception table. It
  368. /// uses the ExceptionTableRegister function.
  369. void RegisterTable(const Function *fn, void* res) {
  370. if (ExceptionTableRegister) {
  371. ExceptionTableRegister(res);
  372. AllExceptionTables[fn] = res;
  373. }
  374. }
  375. /// DeregisterTable - Deregisters the exception frame previously registered
  376. /// for the given function.
  377. void DeregisterTable(const Function *Fn) {
  378. if (ExceptionTableDeregister) {
  379. DenseMap<const Function*, void*>::iterator frame =
  380. AllExceptionTables.find(Fn);
  381. if(frame != AllExceptionTables.end()) {
  382. ExceptionTableDeregister(frame->second);
  383. AllExceptionTables.erase(frame);
  384. }
  385. }
  386. }
  387. /// DeregisterAllTables - Deregisters all previously registered pointers to an
  388. /// exception tables. It uses the ExceptionTableoDeregister function.
  389. void DeregisterAllTables();
  390. protected:
  391. explicit ExecutionEngine(Module *M);
  392. void emitGlobals();
  393. void EmitGlobalVariable(const GlobalVariable *GV);
  394. GenericValue getConstantValue(const Constant *C);
  395. void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
  396. Type *Ty);
  397. };
  398. namespace EngineKind {
  399. // These are actually bitmasks that get or-ed together.
  400. enum Kind {
  401. JIT = 0x1,
  402. Interpreter = 0x2
  403. };
  404. const static Kind Either = (Kind)(JIT | Interpreter);
  405. }
  406. /// EngineBuilder - Builder class for ExecutionEngines. Use this by
  407. /// stack-allocating a builder, chaining the various set* methods, and
  408. /// terminating it with a .create() call.
  409. class EngineBuilder {
  410. private:
  411. Module *M;
  412. EngineKind::Kind WhichEngine;
  413. std::string *ErrorStr;
  414. CodeGenOpt::Level OptLevel;
  415. JITMemoryManager *JMM;
  416. bool AllocateGVsWithCode;
  417. TargetOptions Options;
  418. Reloc::Model RelocModel;
  419. CodeModel::Model CMModel;
  420. std::string MArch;
  421. std::string MCPU;
  422. SmallVector<std::string, 4> MAttrs;
  423. bool UseMCJIT;
  424. /// InitEngine - Does the common initialization of default options.
  425. void InitEngine() {
  426. WhichEngine = EngineKind::Either;
  427. ErrorStr = NULL;
  428. OptLevel = CodeGenOpt::Default;
  429. JMM = NULL;
  430. Options = TargetOptions();
  431. AllocateGVsWithCode = false;
  432. RelocModel = Reloc::Default;
  433. CMModel = CodeModel::JITDefault;
  434. UseMCJIT = false;
  435. }
  436. public:
  437. /// EngineBuilder - Constructor for EngineBuilder. If create() is called and
  438. /// is successful, the created engine takes ownership of the module.
  439. EngineBuilder(Module *m) : M(m) {
  440. InitEngine();
  441. }
  442. /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
  443. /// or whichever engine works. This option defaults to EngineKind::Either.
  444. EngineBuilder &setEngineKind(EngineKind::Kind w) {
  445. WhichEngine = w;
  446. return *this;
  447. }
  448. /// setJITMemoryManager - Sets the memory manager to use. This allows
  449. /// clients to customize their memory allocation policies. If create() is
  450. /// called and is successful, the created engine takes ownership of the
  451. /// memory manager. This option defaults to NULL.
  452. EngineBuilder &setJITMemoryManager(JITMemoryManager *jmm) {
  453. JMM = jmm;
  454. return *this;
  455. }
  456. /// setErrorStr - Set the error string to write to on error. This option
  457. /// defaults to NULL.
  458. EngineBuilder &setErrorStr(std::string *e) {
  459. ErrorStr = e;
  460. return *this;
  461. }
  462. /// setOptLevel - Set the optimization level for the JIT. This option
  463. /// defaults to CodeGenOpt::Default.
  464. EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
  465. OptLevel = l;
  466. return *this;
  467. }
  468. /// setTargetOptions - Set the target options that the ExecutionEngine
  469. /// target is using. Defaults to TargetOptions().
  470. EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
  471. Options = Opts;
  472. return *this;
  473. }
  474. /// setRelocationModel - Set the relocation model that the ExecutionEngine
  475. /// target is using. Defaults to target specific default "Reloc::Default".
  476. EngineBuilder &setRelocationModel(Reloc::Model RM) {
  477. RelocModel = RM;
  478. return *this;
  479. }
  480. /// setCodeModel - Set the CodeModel that the ExecutionEngine target
  481. /// data is using. Defaults to target specific default
  482. /// "CodeModel::JITDefault".
  483. EngineBuilder &setCodeModel(CodeModel::Model M) {
  484. CMModel = M;
  485. return *this;
  486. }
  487. /// setAllocateGVsWithCode - Sets whether global values should be allocated
  488. /// into the same buffer as code. For most applications this should be set
  489. /// to false. Allocating globals with code breaks freeMachineCodeForFunction
  490. /// and is probably unsafe and bad for performance. However, we have clients
  491. /// who depend on this behavior, so we must support it. This option defaults
  492. /// to false so that users of the new API can safely use the new memory
  493. /// manager and free machine code.
  494. EngineBuilder &setAllocateGVsWithCode(bool a) {
  495. AllocateGVsWithCode = a;
  496. return *this;
  497. }
  498. /// setMArch - Override the architecture set by the Module's triple.
  499. EngineBuilder &setMArch(StringRef march) {
  500. MArch.assign(march.begin(), march.end());
  501. return *this;
  502. }
  503. /// setMCPU - Target a specific cpu type.
  504. EngineBuilder &setMCPU(StringRef mcpu) {
  505. MCPU.assign(mcpu.begin(), mcpu.end());
  506. return *this;
  507. }
  508. /// setUseMCJIT - Set whether the MC-JIT implementation should be used
  509. /// (experimental).
  510. EngineBuilder &setUseMCJIT(bool Value) {
  511. UseMCJIT = Value;
  512. return *this;
  513. }
  514. /// setMAttrs - Set cpu-specific attributes.
  515. template<typename StringSequence>
  516. EngineBuilder &setMAttrs(const StringSequence &mattrs) {
  517. MAttrs.clear();
  518. MAttrs.append(mattrs.begin(), mattrs.end());
  519. return *this;
  520. }
  521. TargetMachine *selectTarget();
  522. /// selectTarget - Pick a target either via -march or by guessing the native
  523. /// arch. Add any CPU features specified via -mcpu or -mattr.
  524. TargetMachine *selectTarget(const Triple &TargetTriple,
  525. StringRef MArch,
  526. StringRef MCPU,
  527. const SmallVectorImpl<std::string>& MAttrs);
  528. ExecutionEngine *create() {
  529. return create(selectTarget());
  530. }
  531. ExecutionEngine *create(TargetMachine *TM);
  532. };
  533. } // End llvm namespace
  534. #endif