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