LLVM  13.0.0git
ExecutionEngine.h
Go to the documentation of this file.
1 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the abstract interface that implements execution support
10 // for LLVM.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
15 #define LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
16 
17 #include "llvm-c/ExecutionEngine.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringMap.h"
22 #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 /// 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  /// 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 /// 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, std::string *ErrorStr,
141  std::shared_ptr<MCJITMemoryManager> MM,
142  std::shared_ptr<LegacyJITSymbolResolver> SR,
143  std::unique_ptr<TargetMachine> TM);
144 
145  static ExecutionEngine *(*InterpCtor)(std::unique_ptr<Module> M,
146  std::string *ErrorStr);
147 
148  /// LazyFunctionCreator - If an unknown function is needed, this function
149  /// pointer is invoked to create it. If this returns null, the JIT will
150  /// abort.
152 
153  /// getMangledName - Get mangled name.
154  std::string getMangledName(const GlobalValue *GV);
155 
156  std::string ErrMsg;
157 
158 public:
159  /// lock - This lock protects the ExecutionEngine and MCJIT classes. It must
160  /// be held while changing the internal state of any of those classes.
162 
163  //===--------------------------------------------------------------------===//
164  // ExecutionEngine Startup
165  //===--------------------------------------------------------------------===//
166 
167  virtual ~ExecutionEngine();
168 
169  /// Add a Module to the list of modules that we can JIT from.
170  virtual void addModule(std::unique_ptr<Module> M) {
171  Modules.push_back(std::move(M));
172  }
173 
174  /// addObjectFile - Add an ObjectFile to the execution engine.
175  ///
176  /// This method is only supported by MCJIT. MCJIT will immediately load the
177  /// object into memory and adds its symbols to the list used to resolve
178  /// external symbols while preparing other objects for execution.
179  ///
180  /// Objects added using this function will not be made executable until
181  /// needed by another object.
182  ///
183  /// MCJIT will take ownership of the ObjectFile.
184  virtual void addObjectFile(std::unique_ptr<object::ObjectFile> O);
186 
187  /// addArchive - Add an Archive to the execution engine.
188  ///
189  /// This method is only supported by MCJIT. MCJIT will use the archive to
190  /// resolve external symbols in objects it is loading. If a symbol is found
191  /// in the Archive the contained object file will be extracted (in memory)
192  /// and loaded for possible execution.
194 
195  //===--------------------------------------------------------------------===//
196 
197  const DataLayout &getDataLayout() const { return DL; }
198 
199  /// removeModule - Removes a Module from the list of modules, but does not
200  /// free the module's memory. Returns true if M is found, in which case the
201  /// caller assumes responsibility for deleting the module.
202  //
203  // FIXME: This stealth ownership transfer is horrible. This will probably be
204  // fixed by deleting ExecutionEngine.
205  virtual bool removeModule(Module *M);
206 
207  /// FindFunctionNamed - Search all of the active modules to find the function that
208  /// defines FnName. This is very slow operation and shouldn't be used for
209  /// general code.
210  virtual Function *FindFunctionNamed(StringRef FnName);
211 
212  /// FindGlobalVariableNamed - Search all of the active modules to find the global variable
213  /// that defines Name. This is very slow operation and shouldn't be used for
214  /// general code.
215  virtual GlobalVariable *FindGlobalVariableNamed(StringRef Name, bool AllowInternal = false);
216 
217  /// runFunction - Execute the specified function with the specified arguments,
218  /// and return the result.
219  ///
220  /// For MCJIT execution engines, clients are encouraged to use the
221  /// "GetFunctionAddress" method (rather than runFunction) and cast the
222  /// returned uint64_t to the desired function pointer type. However, for
223  /// backwards compatibility MCJIT's implementation can execute 'main-like'
224  /// function (i.e. those returning void or int, and taking either no
225  /// arguments or (int, char*[])).
227  ArrayRef<GenericValue> ArgValues) = 0;
228 
229  /// getPointerToNamedFunction - This method returns the address of the
230  /// specified function by using the dlsym function call. As such it is only
231  /// useful for resolving library symbols, not code generated symbols.
232  ///
233  /// If AbortOnFailure is false and no function with the given name is
234  /// found, this function silently returns a null pointer. Otherwise,
235  /// it prints a message to stderr and aborts.
236  ///
237  /// This function is deprecated for the MCJIT execution engine.
239  bool AbortOnFailure = true) = 0;
240 
241  /// mapSectionAddress - map a section to its target address space value.
242  /// Map the address of a JIT section as returned from the memory manager
243  /// to the address in the target process as the running code will see it.
244  /// This is the address which will be used for relocation resolution.
245  virtual void mapSectionAddress(const void *LocalAddress,
246  uint64_t TargetAddress) {
247  llvm_unreachable("Re-mapping of section addresses not supported with this "
248  "EE!");
249  }
250 
251  /// generateCodeForModule - Run code generation for the specified module and
252  /// load it into memory.
253  ///
254  /// When this function has completed, all code and data for the specified
255  /// module, and any module on which this module depends, will be generated
256  /// and loaded into memory, but relocations will not yet have been applied
257  /// and all memory will be readable and writable but not executable.
258  ///
259  /// This function is primarily useful when generating code for an external
260  /// target, allowing the client an opportunity to remap section addresses
261  /// before relocations are applied. Clients that intend to execute code
262  /// locally can use the getFunctionAddress call, which will generate code
263  /// and apply final preparations all in one step.
264  ///
265  /// This method has no effect for the interpeter.
266  virtual void generateCodeForModule(Module *M) {}
267 
268  /// finalizeObject - ensure the module is fully processed and is usable.
269  ///
270  /// It is the user-level function for completing the process of making the
271  /// object usable for execution. It should be called after sections within an
272  /// object have been relocated using mapSectionAddress. When this method is
273  /// called the MCJIT execution engine will reapply relocations for a loaded
274  /// object. This method has no effect for the interpeter.
275  ///
276  /// Returns true on success, false on failure. Error messages can be retrieved
277  /// by calling getError();
278  virtual void finalizeObject() {}
279 
280  /// Returns true if an error has been recorded.
281  bool hasError() const { return !ErrMsg.empty(); }
282 
283  /// Clear the error message.
284  void clearErrorMessage() { ErrMsg.clear(); }
285 
286  /// Returns the most recent error message.
287  const std::string &getErrorMessage() const { return ErrMsg; }
288 
289  /// runStaticConstructorsDestructors - This method is used to execute all of
290  /// the static constructors or destructors for a program.
291  ///
292  /// \param isDtors - Run the destructors instead of constructors.
293  virtual void runStaticConstructorsDestructors(bool isDtors);
294 
295  /// This method is used to execute all of the static constructors or
296  /// destructors for a particular module.
297  ///
298  /// \param isDtors - Run the destructors instead of constructors.
299  void runStaticConstructorsDestructors(Module &module, bool isDtors);
300 
301 
302  /// runFunctionAsMain - This is a helper function which wraps runFunction to
303  /// handle the common task of starting up main with the specified argc, argv,
304  /// and envp parameters.
305  int runFunctionAsMain(Function *Fn, const std::vector<std::string> &argv,
306  const char * const * envp);
307 
308 
309  /// addGlobalMapping - Tell the execution engine that the specified global is
310  /// at the specified location. This is used internally as functions are JIT'd
311  /// and as global variables are laid out in memory. It can and should also be
312  /// used by clients of the EE that want to have an LLVM global overlay
313  /// existing data in memory. Values to be mapped should be named, and have
314  /// external or weak linkage. Mappings are automatically removed when their
315  /// GlobalValue is destroyed.
316  void addGlobalMapping(const GlobalValue *GV, void *Addr);
317  void addGlobalMapping(StringRef Name, uint64_t Addr);
318 
319  /// clearAllGlobalMappings - Clear all global mappings and start over again,
320  /// for use in dynamic compilation scenarios to move globals.
321  void clearAllGlobalMappings();
322 
323  /// clearGlobalMappingsFromModule - Clear all global mappings that came from a
324  /// particular module, because it has been removed from the JIT.
326 
327  /// updateGlobalMapping - Replace an existing mapping for GV with a new
328  /// address. This updates both maps as required. If "Addr" is null, the
329  /// entry for the global is removed from the mappings. This returns the old
330  /// value of the pointer, or null if it was not in the map.
331  uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr);
332  uint64_t updateGlobalMapping(StringRef Name, uint64_t Addr);
333 
334  /// getAddressToGlobalIfAvailable - This returns the address of the specified
335  /// global symbol.
337 
338  /// getPointerToGlobalIfAvailable - This returns the address of the specified
339  /// global value if it is has already been codegen'd, otherwise it returns
340  /// null.
343 
344  /// getPointerToGlobal - This returns the address of the specified global
345  /// value. This may involve code generation if it's a function.
346  ///
347  /// This function is deprecated for the MCJIT execution engine. Use
348  /// getGlobalValueAddress instead.
349  void *getPointerToGlobal(const GlobalValue *GV);
350 
351  /// getPointerToFunction - The different EE's represent function bodies in
352  /// different ways. They should each implement this to say what a function
353  /// pointer should look like. When F is destroyed, the ExecutionEngine will
354  /// remove its global mapping and free any machine code. Be sure no threads
355  /// are running inside F when that happens.
356  ///
357  /// This function is deprecated for the MCJIT execution engine. Use
358  /// getFunctionAddress instead.
359  virtual void *getPointerToFunction(Function *F) = 0;
360 
361  /// getPointerToFunctionOrStub - If the specified function has been
362  /// code-gen'd, return a pointer to the function. If not, compile it, or use
363  /// a stub to implement lazy compilation if available. See
364  /// getPointerToFunction for the requirements on destroying F.
365  ///
366  /// This function is deprecated for the MCJIT execution engine. Use
367  /// getFunctionAddress instead.
369  // Default implementation, just codegen the function.
370  return getPointerToFunction(F);
371  }
372 
373  /// getGlobalValueAddress - Return the address of the specified global
374  /// value. This may involve code generation.
375  ///
376  /// This function should not be called with the interpreter engine.
377  virtual uint64_t getGlobalValueAddress(const std::string &Name) {
378  // Default implementation for the interpreter. MCJIT will override this.
379  // JIT and interpreter clients should use getPointerToGlobal instead.
380  return 0;
381  }
382 
383  /// getFunctionAddress - Return the address of the specified function.
384  /// This may involve code generation.
385  virtual uint64_t getFunctionAddress(const std::string &Name) {
386  // Default implementation for the interpreter. MCJIT will override this.
387  // Interpreter clients should use getPointerToFunction instead.
388  return 0;
389  }
390 
391  /// getGlobalValueAtAddress - Return the LLVM global value object that starts
392  /// at the specified address.
393  ///
395 
396  /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
397  /// Ptr is the address of the memory at which to store Val, cast to
398  /// GenericValue *. It is not a pointer to a GenericValue containing the
399  /// address at which to store Val.
400  void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
401  Type *Ty);
402 
403  void InitializeMemory(const Constant *Init, void *Addr);
404 
405  /// getOrEmitGlobalVariable - Return the address of the specified global
406  /// variable, possibly emitting it to memory if needed. This is used by the
407  /// Emitter.
408  ///
409  /// This function is deprecated for the MCJIT execution engine. Use
410  /// getGlobalValueAddress instead.
411  virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) {
412  return getPointerToGlobal((const GlobalValue *)GV);
413  }
414 
415  /// Registers a listener to be called back on various events within
416  /// the JIT. See JITEventListener.h for more details. Does not
417  /// take ownership of the argument. The argument may be NULL, in
418  /// which case these functions do nothing.
421 
422  /// Sets the pre-compiled object cache. The ownership of the ObjectCache is
423  /// not changed. Supported by MCJIT but not the interpreter.
424  virtual void setObjectCache(ObjectCache *) {
425  llvm_unreachable("No support for an object cache");
426  }
427 
428  /// setProcessAllSections (MCJIT Only): By default, only sections that are
429  /// "required for execution" are passed to the RTDyldMemoryManager, and other
430  /// sections are discarded. Passing 'true' to this method will cause
431  /// RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless
432  /// of whether they are "required to execute" in the usual sense.
433  ///
434  /// Rationale: Some MCJIT clients want to be able to inspect metadata
435  /// sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze
436  /// performance. Passing these sections to the memory manager allows the
437  /// client to make policy about the relevant sections, rather than having
438  /// MCJIT do it.
439  virtual void setProcessAllSections(bool ProcessAllSections) {
440  llvm_unreachable("No support for ProcessAllSections option");
441  }
442 
443  /// Return the target machine (if available).
444  virtual TargetMachine *getTargetMachine() { return nullptr; }
445 
446  /// DisableLazyCompilation - When lazy compilation is off (the default), the
447  /// JIT will eagerly compile every function reachable from the argument to
448  /// getPointerToFunction. If lazy compilation is turned on, the JIT will only
449  /// compile the one function and emit stubs to compile the rest when they're
450  /// first called. If lazy compilation is turned off again while some lazy
451  /// stubs are still around, and one of those stubs is called, the program will
452  /// abort.
453  ///
454  /// In order to safely compile lazily in a threaded program, the user must
455  /// ensure that 1) only one thread at a time can call any particular lazy
456  /// stub, and 2) any thread modifying LLVM IR must hold the JIT's lock
457  /// (ExecutionEngine::lock) or otherwise ensure that no other thread calls a
458  /// lazy stub. See http://llvm.org/PR5184 for details.
459  void DisableLazyCompilation(bool Disabled = true) {
460  CompilingLazily = !Disabled;
461  }
462  bool isCompilingLazily() const {
463  return CompilingLazily;
464  }
465 
466  /// DisableGVCompilation - If called, the JIT will abort if it's asked to
467  /// allocate space and populate a GlobalVariable that is not internal to
468  /// the module.
469  void DisableGVCompilation(bool Disabled = true) {
470  GVCompilationDisabled = Disabled;
471  }
472  bool isGVCompilationDisabled() const {
473  return GVCompilationDisabled;
474  }
475 
476  /// DisableSymbolSearching - If called, the JIT will not try to lookup unknown
477  /// symbols with dlsym. A client can still use InstallLazyFunctionCreator to
478  /// resolve symbols in a custom way.
479  void DisableSymbolSearching(bool Disabled = true) {
480  SymbolSearchingDisabled = Disabled;
481  }
483  return SymbolSearchingDisabled;
484  }
485 
486  /// Enable/Disable IR module verification.
487  ///
488  /// Note: Module verification is enabled by default in Debug builds, and
489  /// disabled by default in Release. Use this method to override the default.
491  VerifyModules = Verify;
492  }
493  bool getVerifyModules() const {
494  return VerifyModules;
495  }
496 
497  /// InstallLazyFunctionCreator - If an unknown function is needed, the
498  /// specified function pointer is invoked to create it. If it returns null,
499  /// the JIT will abort.
502  }
503 
504 protected:
506  explicit ExecutionEngine(DataLayout DL, std::unique_ptr<Module> M);
507  explicit ExecutionEngine(std::unique_ptr<Module> M);
508 
509  void emitGlobals();
510 
511  void emitGlobalVariable(const GlobalVariable *GV);
512 
514  void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
515  Type *Ty);
516 
517 private:
518  void Init(std::unique_ptr<Module> M);
519 };
520 
521 namespace EngineKind {
522 
523  // These are actually bitmasks that get or-ed together.
524  enum Kind {
525  JIT = 0x1,
527  };
528  const static Kind Either = (Kind)(JIT | Interpreter);
529 
530 } // end namespace EngineKind
531 
532 /// Builder class for ExecutionEngines. Use this by stack-allocating a builder,
533 /// chaining the various set* methods, and terminating it with a .create()
534 /// call.
536 private:
537  std::unique_ptr<Module> M;
538  EngineKind::Kind WhichEngine;
539  std::string *ErrorStr;
540  CodeGenOpt::Level OptLevel;
541  std::shared_ptr<MCJITMemoryManager> MemMgr;
542  std::shared_ptr<LegacyJITSymbolResolver> Resolver;
543  TargetOptions Options;
544  Optional<Reloc::Model> RelocModel;
546  std::string MArch;
547  std::string MCPU;
549  bool VerifyModules;
550  bool EmulatedTLS = true;
551 
552 public:
553  /// Default constructor for EngineBuilder.
554  EngineBuilder();
555 
556  /// Constructor for EngineBuilder.
557  EngineBuilder(std::unique_ptr<Module> M);
558 
559  // Out-of-line since we don't have the def'n of RTDyldMemoryManager here.
560  ~EngineBuilder();
561 
562  /// setEngineKind - Controls whether the user wants the interpreter, the JIT,
563  /// or whichever engine works. This option defaults to EngineKind::Either.
565  WhichEngine = w;
566  return *this;
567  }
568 
569  /// setMCJITMemoryManager - Sets the MCJIT memory manager to use. This allows
570  /// clients to customize their memory allocation policies for the MCJIT. This
571  /// is only appropriate for the MCJIT; setting this and configuring the builder
572  /// to create anything other than MCJIT will cause a runtime error. If create()
573  /// is called and is successful, the created engine takes ownership of the
574  /// memory manager. This option defaults to NULL.
575  EngineBuilder &setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
576 
578  setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
579 
580  EngineBuilder &setSymbolResolver(std::unique_ptr<LegacyJITSymbolResolver> SR);
581 
582  /// setErrorStr - Set the error string to write to on error. This option
583  /// defaults to NULL.
584  EngineBuilder &setErrorStr(std::string *e) {
585  ErrorStr = e;
586  return *this;
587  }
588 
589  /// setOptLevel - Set the optimization level for the JIT. This option
590  /// defaults to CodeGenOpt::Default.
592  OptLevel = l;
593  return *this;
594  }
595 
596  /// setTargetOptions - Set the target options that the ExecutionEngine
597  /// target is using. Defaults to TargetOptions().
599  Options = Opts;
600  return *this;
601  }
602 
603  /// setRelocationModel - Set the relocation model that the ExecutionEngine
604  /// target is using. Defaults to target specific default "Reloc::Default".
606  RelocModel = RM;
607  return *this;
608  }
609 
610  /// setCodeModel - Set the CodeModel that the ExecutionEngine target
611  /// data is using. Defaults to target specific default
612  /// "CodeModel::JITDefault".
614  CMModel = M;
615  return *this;
616  }
617 
618  /// setMArch - Override the architecture set by the Module's triple.
620  MArch.assign(march.begin(), march.end());
621  return *this;
622  }
623 
624  /// setMCPU - Target a specific cpu type.
626  MCPU.assign(mcpu.begin(), mcpu.end());
627  return *this;
628  }
629 
630  /// setVerifyModules - Set whether the JIT implementation should verify
631  /// IR modules during compilation.
633  VerifyModules = Verify;
634  return *this;
635  }
636 
637  /// setMAttrs - Set cpu-specific attributes.
638  template<typename StringSequence>
639  EngineBuilder &setMAttrs(const StringSequence &mattrs) {
640  MAttrs.clear();
641  MAttrs.append(mattrs.begin(), mattrs.end());
642  return *this;
643  }
644 
645  void setEmulatedTLS(bool EmulatedTLS) {
646  this->EmulatedTLS = EmulatedTLS;
647  }
648 
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 
663 };
664 
665 // Create wrappers for C Binding types (see CBindingWrapping.h).
667 
668 } // end namespace llvm
669 
670 #endif // LLVM_EXECUTIONENGINE_EXECUTIONENGINE_H
llvm::EngineKind::Kind
Kind
Definition: ExecutionEngine.h:524
llvm::ExecutionEngine::getMangledName
std::string getMangledName(const GlobalValue *GV)
getMangledName - Get mangled name.
Definition: ExecutionEngine.cpp:188
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::ExecutionEngine::setVerifyModules
void setVerifyModules(bool Verify)
Enable/Disable IR module verification.
Definition: ExecutionEngine.h:490
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::TailPredication::Disabled
@ Disabled
Definition: ARMTargetTransformInfo.h:43
llvm::ExecutionEngine::getPointerToFunctionOrStub
virtual void * getPointerToFunctionOrStub(Function *F)
getPointerToFunctionOrStub - If the specified function has been code-gen'd, return a pointer to the f...
Definition: ExecutionEngine.h:368
JITSymbol.h
llvm::SystemZISD::TM
@ TM
Definition: SystemZISelLowering.h:65
llvm::ExecutionEngine::~ExecutionEngine
virtual ~ExecutionEngine()
Definition: ExecutionEngine.cpp:90
Optional.h
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:111
llvm::TargetOptions
Definition: TargetOptions.h:122
llvm::EngineBuilder::create
ExecutionEngine * create()
Definition: ExecutionEngine.h:658
llvm::ExecutionEngine::updateGlobalMapping
uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr)
updateGlobalMapping - Replace an existing mapping for GV with a new address.
Definition: ExecutionEngine.cpp:241
llvm::EngineBuilder::setCodeModel
EngineBuilder & setCodeModel(CodeModel::Model M)
setCodeModel - Set the CodeModel that the ExecutionEngine target data is using.
Definition: ExecutionEngine.h:613
llvm::Function
Definition: Function.h:61
StringRef.h
llvm::EngineBuilder::setMCJITMemoryManager
EngineBuilder & setMCJITMemoryManager(std::unique_ptr< RTDyldMemoryManager > mcjmm)
setMCJITMemoryManager - Sets the MCJIT memory manager to use.
Definition: ExecutionEngine.cpp:486
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
LLVMExecutionEngineRef
struct LLVMOpaqueExecutionEngine * LLVMExecutionEngineRef
Definition: ExecutionEngine.h:40
ErrorHandling.h
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::ExecutionEngine::getPointerToNamedFunction
virtual void * getPointerToNamedFunction(StringRef Name, bool AbortOnFailure=true)=0
getPointerToNamedFunction - This method returns the address of the specified function by using the dl...
llvm::ExecutionEngine::clearGlobalMappingsFromModule
void clearGlobalMappingsFromModule(Module *M)
clearGlobalMappingsFromModule - Clear all global mappings that came from a particular module,...
Definition: ExecutionEngine.cpp:234
llvm::ExecutionEngine::runFunctionAsMain
int runFunctionAsMain(Function *Fn, const std::vector< std::string > &argv, const char *const *envp)
runFunctionAsMain - This is a helper function which wraps runFunction to handle the common task of st...
Definition: ExecutionEngine.cpp:423
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::ExecutionEngine::clearAllGlobalMappings
void clearAllGlobalMappings()
clearAllGlobalMappings - Clear all global mappings and start over again, for use in dynamic compilati...
Definition: ExecutionEngine.cpp:227
llvm::ExecutionEngine::emitGlobalVariable
void emitGlobalVariable(const GlobalVariable *GV)
Definition: ExecutionEngine.cpp:1288
llvm::ExecutionEngine::getTargetMachine
virtual TargetMachine * getTargetMachine()
Return the target machine (if available).
Definition: ExecutionEngine.h:444
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
Module.h
llvm::ExecutionEngine::isSymbolSearchingDisabled
bool isSymbolSearchingDisabled() const
Definition: ExecutionEngine.h:482
llvm::EngineBuilder
Builder class for ExecutionEngines.
Definition: ExecutionEngine.h:535
llvm::EngineBuilder::setTargetOptions
EngineBuilder & setTargetOptions(const TargetOptions &Opts)
setTargetOptions - Set the target options that the ExecutionEngine target is using.
Definition: ExecutionEngine.h:598
llvm::ObjectCache
This is the base ObjectCache type which can be provided to an ExecutionEngine for the purpose of avoi...
Definition: ObjectCache.h:23
llvm::ExecutionEngine::mapSectionAddress
virtual void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress)
mapSectionAddress - map a section to its target address space value.
Definition: ExecutionEngine.h:245
llvm::Optional< Reloc::Model >
CBindingWrapping.h
llvm::ExecutionEngine::Modules
SmallVector< std::unique_ptr< Module >, 1 > Modules
The list of Modules that we are JIT'ing from.
Definition: ExecutionEngine.h:134
llvm::ExecutionEngine::DisableSymbolSearching
void DisableSymbolSearching(bool Disabled=true)
DisableSymbolSearching - If called, the JIT will not try to lookup unknown symbols with dlsym.
Definition: ExecutionEngine.h:479
llvm::ExecutionEngine::DisableGVCompilation
void DisableGVCompilation(bool Disabled=true)
DisableGVCompilation - If called, the JIT will abort if it's asked to allocate space and populate a G...
Definition: ExecutionEngine.h:469
F
#define F(x, y, z)
Definition: MD5.cpp:56
DEFINE_SIMPLE_CONVERSION_FUNCTIONS
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Definition: CBindingWrapping.h:19
llvm::Reloc::Model
Model
Definition: CodeGen.h:22
llvm::ExecutionEngine::StoreValueToMemory
void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr, Type *Ty)
StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
Definition: ExecutionEngine.cpp:1018
llvm::Resolver
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:1983
llvm::ExecutionEngine::lock
sys::Mutex lock
lock - This lock protects the ExecutionEngine and MCJIT classes.
Definition: ExecutionEngine.h:161
llvm::ExecutionEngine::LoadValueFromMemory
void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr, Type *Ty)
FIXME: document.
Definition: ExecutionEngine.cpp:1068
llvm::GenericValue
Definition: GenericValue.h:23
llvm::ExecutionEngine::addObjectFile
virtual void addObjectFile(std::unique_ptr< object::ObjectFile > O)
addObjectFile - Add an ObjectFile to the execution engine.
Definition: ExecutionEngine.cpp:127
TargetMachine.h
llvm::ExecutionEngine::getAddressToGlobalIfAvailable
uint64_t getAddressToGlobalIfAvailable(StringRef S)
getAddressToGlobalIfAvailable - This returns the address of the specified global symbol.
Definition: ExecutionEngine.cpp:274
llvm::ExecutionEngine::isGVCompilationDisabled
bool isGVCompilationDisabled() const
Definition: ExecutionEngine.h:472
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:69
llvm::ExecutionEngine::getVerifyModules
bool getVerifyModules() const
Definition: ExecutionEngine.h:493
llvm::ExecutionEngine::generateCodeForModule
virtual void generateCodeForModule(Module *M)
generateCodeForModule - Run code generation for the specified module and load it into memory.
Definition: ExecutionEngine.h:266
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:648
llvm::ExecutionEngine::addModule
virtual void addModule(std::unique_ptr< Module > M)
Add a Module to the list of modules that we can JIT from.
Definition: ExecutionEngine.h:170
llvm::ExecutionEngine::getOrEmitGlobalVariable
virtual void * getOrEmitGlobalVariable(const GlobalVariable *GV)
getOrEmitGlobalVariable - Return the address of the specified global variable, possibly emitting it t...
Definition: ExecutionEngine.h:411
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ExecutionEngine::LazyFunctionCreator
FunctionCreator LazyFunctionCreator
LazyFunctionCreator - If an unknown function is needed, this function pointer is invoked to create it...
Definition: ExecutionEngine.h:151
llvm::ExecutionEngine::getFunctionAddress
virtual uint64_t getFunctionAddress(const std::string &Name)
getFunctionAddress - Return the address of the specified function.
Definition: ExecutionEngine.h:385
llvm::ExecutionEngine::FindGlobalVariableNamed
virtual GlobalVariable * FindGlobalVariableNamed(StringRef Name, bool AllowInternal=false)
FindGlobalVariableNamed - Search all of the active modules to find the global variable that defines N...
Definition: ExecutionEngine.cpp:162
l
This requires reassociating to forms of expressions that are already something that reassoc doesn t think about yet These two functions should generate the same code on big endian int * l
Definition: README.txt:100
llvm::EngineBuilder::setErrorStr
EngineBuilder & setErrorStr(std::string *e)
setErrorStr - Set the error string to write to on error.
Definition: ExecutionEngine.h:584
llvm::ExecutionEngine::FindFunctionNamed
virtual Function * FindFunctionNamed(StringRef FnName)
FindFunctionNamed - Search all of the active modules to find the function that defines FnName.
Definition: ExecutionEngine.cpp:153
llvm::ExecutionEngine::DisableLazyCompilation
void DisableLazyCompilation(bool Disabled=true)
DisableLazyCompilation - When lazy compilation is off (the default), the JIT will eagerly compile eve...
Definition: ExecutionEngine.h:459
llvm::ExecutionEngineState::RemoveMapping
uint64_t RemoveMapping(StringRef Name)
Erase an entry from the mapping table.
Definition: ExecutionEngine.cpp:171
llvm::ExecutionEngine::getConstantValue
GenericValue getConstantValue(const Constant *C)
Converts a Constant* into a GenericValue, including handling of ConstantExpr values.
Definition: ExecutionEngine.cpp:585
llvm::EngineBuilder::setVerifyModules
EngineBuilder & setVerifyModules(bool Verify)
setVerifyModules - Set whether the JIT implementation should verify IR modules during compilation.
Definition: ExecutionEngine.h:632
llvm::ExecutionEngine::setObjectCache
virtual void setObjectCache(ObjectCache *)
Sets the pre-compiled object cache.
Definition: ExecutionEngine.h:424
StringMap.h
llvm::EngineBuilder::setMemoryManager
EngineBuilder & setMemoryManager(std::unique_ptr< MCJITMemoryManager > MM)
Definition: ExecutionEngine.cpp:495
llvm::sys::SmartMutex< false >
llvm::StringMap< uint64_t >
llvm::ExecutionEngine::UnregisterJITEventListener
virtual void UnregisterJITEventListener(JITEventListener *)
Definition: ExecutionEngine.h:420
llvm::ExecutionEngine::clearErrorMessage
void clearErrorMessage()
Clear the error message.
Definition: ExecutionEngine.h:284
llvm::ExecutionEngine::removeModule
virtual bool removeModule(Module *M)
removeModule - Removes a Module from the list of modules, but does not free the module's memory.
Definition: ExecutionEngine.cpp:140
llvm::ExecutionEngine::runStaticConstructorsDestructors
virtual void runStaticConstructorsDestructors(bool isDtors)
runStaticConstructorsDestructors - This method is used to execute all of the static constructors or d...
Definition: ExecutionEngine.cpp:406
llvm::ExecutionEngine::getDataLayout
const DataLayout & getDataLayout() const
Definition: ExecutionEngine.h:197
llvm::CodeModel::Model
Model
Definition: CodeGen.h:28
llvm::ExecutionEngine::finalizeObject
virtual void finalizeObject()
finalizeObject - ensure the module is fully processed and is usable.
Definition: ExecutionEngine.h:278
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:128
llvm::GlobalValue
Definition: GlobalValue.h:44
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
Verify
ppc ctr loops PowerPC CTR Loops Verify
Definition: PPCCTRLoops.cpp:77
llvm::EngineBuilder::setRelocationModel
EngineBuilder & setRelocationModel(Reloc::Model RM)
setRelocationModel - Set the relocation model that the ExecutionEngine target is using.
Definition: ExecutionEngine.h:605
llvm::StringRef::end
iterator end() const
Definition: StringRef.h:133
llvm::EngineKind::JIT
@ JIT
Definition: ExecutionEngine.h:525
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:58
llvm::ExecutionEngine::InstallLazyFunctionCreator
void InstallLazyFunctionCreator(FunctionCreator C)
InstallLazyFunctionCreator - If an unknown function is needed, the specified function pointer is invo...
Definition: ExecutionEngine.h:500
llvm::ExecutionEngine::ErrMsg
std::string ErrMsg
Definition: ExecutionEngine.h:156
llvm::ExecutionEngineState::getGlobalAddressMap
GlobalAddressMapTy & getGlobalAddressMap()
Definition: ExecutionEngine.h:81
ArrayRef.h
TemplateParamKind::Type
@ Type
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
OrcV1Deprecation.h
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1556
llvm::EngineBuilder::EngineBuilder
EngineBuilder()
Default constructor for EngineBuilder.
Definition: ExecutionEngine.cpp:470
llvm::ExecutionEngine::getPointerToFunction
virtual void * getPointerToFunction(Function *F)=0
getPointerToFunction - The different EE's represent function bodies in different ways.
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::codeview::CodeViewContainer::ObjectFile
@ ObjectFile
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::ExecutionEngine::getGlobalValueAtAddress
const GlobalValue * getGlobalValueAtAddress(void *Addr)
getGlobalValueAtAddress - Return the LLVM global value object that starts at the specified address.
Definition: ExecutionEngine.cpp:297
llvm::EngineKind::Either
const static Kind Either
Definition: ExecutionEngine.h:528
llvm::ExecutionEngine::hasError
bool hasError() const
Returns true if an error has been recorded.
Definition: ExecutionEngine.h:281
llvm::JITEventListener
JITEventListener - Abstract interface for use by the JIT to notify clients about significant events d...
Definition: JITEventListener.h:41
TargetOptions.h
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:463
llvm::ExecutionEngineState::getGlobalAddressReverseMap
std::map< uint64_t, std::string > & getGlobalAddressReverseMap()
Definition: ExecutionEngine.h:85
llvm::ExecutionEngine::ExecutionEngine
ExecutionEngine(DataLayout DL)
Definition: ExecutionEngine.h:505
llvm::ExecutionEngine::getPointerToGlobal
void * getPointerToGlobal(const GlobalValue *GV)
getPointerToGlobal - This returns the address of the specified global value.
Definition: ExecutionEngine.cpp:565
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::ExecutionEngine::addGlobalMapping
void addGlobalMapping(const GlobalValue *GV, void *Addr)
addGlobalMapping - Tell the execution engine that the specified global is at the specified location.
Definition: ExecutionEngine.cpp:203
DataLayout.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
A
* A
Definition: README_ALTIVEC.txt:89
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
Mutex.h
llvm::FunctionCreator
std::function< void *(const std::string &)> FunctionCreator
Definition: ExecutionEngine.h:95
llvm::Init
Definition: Record.h:271
llvm::EngineBuilder::setEmulatedTLS
void setEmulatedTLS(bool EmulatedTLS)
Definition: ExecutionEngine.h:645
llvm::EngineBuilder::~EngineBuilder
~EngineBuilder()
llvm::ExecutionEngine
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
Definition: ExecutionEngine.h:100
llvm::ExecutionEngine::InitializeMemory
void InitializeMemory(const Constant *Init, void *Addr)
Definition: ExecutionEngine.cpp:1132
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:941
llvm::object::OwningBinary
Definition: RuntimeDyld.h:36
llvm::ExecutionEngine::emitGlobals
void emitGlobals()
EmitGlobals - Emit all of the global variables to memory, storing their addresses into GlobalAddress.
Definition: ExecutionEngine.cpp:1188
llvm::ExecutionEngine::runFunction
virtual GenericValue runFunction(Function *F, ArrayRef< GenericValue > ArgValues)=0
runFunction - Execute the specified function with the specified arguments, and return the result.
llvm::ExecutionEngine::getPointerToGlobalIfAvailable
void * getPointerToGlobalIfAvailable(StringRef S)
getPointerToGlobalIfAvailable - This returns the address of the specified global value if it is has a...
Definition: ExecutionEngine.cpp:285
llvm::ExecutionEngine::RegisterJITEventListener
virtual void RegisterJITEventListener(JITEventListener *)
Registers a listener to be called back on various events within the JIT.
Definition: ExecutionEngine.h:419
llvm::ExecutionEngine::isCompilingLazily
bool isCompilingLazily() const
Definition: ExecutionEngine.h:462
ExecutionEngine.h
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
llvm::EngineBuilder::setMAttrs
EngineBuilder & setMAttrs(const StringSequence &mattrs)
setMAttrs - Set cpu-specific attributes.
Definition: ExecutionEngine.h:639
llvm::EngineBuilder::setSymbolResolver
EngineBuilder & setSymbolResolver(std::unique_ptr< LegacyJITSymbolResolver > SR)
Definition: ExecutionEngine.cpp:501
CodeGen.h
llvm::ExecutionEngine::getMemoryForGV
virtual char * getMemoryForGV(const GlobalVariable *GV)
getMemoryforGV - Allocate memory for a global variable.
Definition: ExecutionEngine.cpp:123
Binary.h
llvm::Interpreter
Definition: Interpreter.h:74
SmallVector.h
llvm::ExecutionEngine::getGlobalValueAddress
virtual uint64_t getGlobalValueAddress(const std::string &Name)
getGlobalValueAddress - Return the address of the specified global value.
Definition: ExecutionEngine.h:377
llvm::ExecutionEngineState
Helper class for helping synchronize access to the global address map table.
Definition: ExecutionEngine.h:65
llvm::EngineBuilder::setMCPU
EngineBuilder & setMCPU(StringRef mcpu)
setMCPU - Target a specific cpu type.
Definition: ExecutionEngine.h:625
llvm::EngineBuilder::setOptLevel
EngineBuilder & setOptLevel(CodeGenOpt::Level l)
setOptLevel - Set the optimization level for the JIT.
Definition: ExecutionEngine.h:591
llvm::SmallVectorImpl< std::string >
llvm::EngineBuilder::setEngineKind
EngineBuilder & setEngineKind(EngineKind::Kind w)
setEngineKind - Controls whether the user wants the interpreter, the JIT, or whichever engine works.
Definition: ExecutionEngine.h:564
llvm::ExecutionEngine::getErrorMessage
const std::string & getErrorMessage() const
Returns the most recent error message.
Definition: ExecutionEngine.h:287
llvm::EngineBuilder::setMArch
EngineBuilder & setMArch(StringRef march)
setMArch - Override the architecture set by the Module's triple.
Definition: ExecutionEngine.h:619
llvm::StringRef::begin
iterator begin() const
Definition: StringRef.h:131
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::EngineBuilder::selectTarget
TargetMachine * selectTarget()
Definition: TargetSelect.cpp:26
llvm::ExecutionEngine::setProcessAllSections
virtual void setProcessAllSections(bool ProcessAllSections)
setProcessAllSections (MCJIT Only): By default, only sections that are "required for execution" are p...
Definition: ExecutionEngine.h:439
llvm::ExecutionEngine::addArchive
virtual void addArchive(object::OwningBinary< object::Archive > A)
addArchive - Add an Archive to the execution engine.
Definition: ExecutionEngine.cpp:136