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