LLVM 23.0.0git
LLJIT.h
Go to the documentation of this file.
1//===----- LLJIT.h -- An ORC-based JIT for compiling LLVM IR ----*- 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// An ORC-based JIT for compiling LLVM IR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_LLJIT_H
14#define LLVM_EXECUTIONENGINE_ORC_LLJIT_H
15
16#include "llvm/ADT/SmallSet.h"
28#include "llvm/Support/Debug.h"
30#include <variant>
31
32namespace llvm {
33namespace orc {
34
39
40/// A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
41///
42/// Create instances using LLJITBuilder.
44 template <typename, typename, typename> friend class LLJITBuilderSetters;
45
47
48public:
49 /// Initializer support for LLJIT.
51 public:
53
54 virtual Error initialize(JITDylib &JD) = 0;
55
56 virtual Error deinitialize(JITDylib &JD) = 0;
57
58 protected:
59 static void setInitTransform(LLJIT &J,
61 };
62
63 /// Destruct this instance. If a multi-threaded instance, waits for all
64 /// compile threads to complete.
65 virtual ~LLJIT();
66
67 /// Returns the ExecutionSession for this instance.
69
70 /// Returns a reference to the triple for this instance.
71 const Triple &getTargetTriple() const { return TT; }
72
73 /// Returns a reference to the DataLayout for this instance.
74 const DataLayout &getDataLayout() const { return DL; }
75
76 /// Returns a reference to the JITDylib representing the JIT'd main program.
78
79 /// Returns the ProcessSymbols JITDylib, which by default reflects non-JIT'd
80 /// symbols in the host process.
81 ///
82 /// Note: JIT'd code should not be added to the ProcessSymbols JITDylib. Use
83 /// the main JITDylib or a custom JITDylib instead.
84 JITDylibSP getProcessSymbolsJITDylib();
85
86 /// Returns the Platform JITDylib, which will contain the ORC runtime (if
87 /// given) and any platform symbols.
88 ///
89 /// Note: JIT'd code should not be added to the Platform JITDylib. Use the
90 /// main JITDylib or a custom JITDylib instead.
91 JITDylibSP getPlatformJITDylib();
92
93 /// Returns the JITDylib with the given name, or nullptr if no JITDylib with
94 /// that name exists.
96 return ES->getJITDylibByName(Name);
97 }
98
99 /// Load a (real) dynamic library and make its symbols available through a
100 /// new JITDylib with the same name.
101 ///
102 /// If the given *executor* path contains a valid platform dynamic library
103 /// then that library will be loaded, and a new bare JITDylib whose name is
104 /// the given path will be created to make the library's symbols available to
105 /// JIT'd code.
106 Expected<JITDylib &> loadPlatformDynamicLibrary(const char *Path);
107
108 /// Link a static library into the given JITDylib.
109 ///
110 /// If the given MemoryBuffer contains a valid static archive (or a universal
111 /// binary with an archive slice that fits the LLJIT instance's platform /
112 /// architecture) then it will be added to the given JITDylib using a
113 /// StaticLibraryDefinitionGenerator.
114 Error linkStaticLibraryInto(JITDylib &JD,
115 std::unique_ptr<MemoryBuffer> LibBuffer);
116
117 /// Link a static library into the given JITDylib.
118 ///
119 /// If the given *host* path contains a valid static archive (or a universal
120 /// binary with an archive slice that fits the LLJIT instance's platform /
121 /// architecture) then it will be added to the given JITDylib using a
122 /// StaticLibraryDefinitionGenerator.
123 Error linkStaticLibraryInto(JITDylib &JD, const char *Path);
124
125 /// Create a new JITDylib with the given name and return a reference to it.
126 ///
127 /// JITDylib names must be unique. If the given name is derived from user
128 /// input or elsewhere in the environment then the client should check
129 /// (e.g. by calling getJITDylibByName) that the given name is not already in
130 /// use.
131 Expected<JITDylib &> createJITDylib(std::string Name);
132
133 /// Returns the default link order for this LLJIT instance. This link order
134 /// will be appended to the link order of JITDylibs created by LLJIT's
135 /// createJITDylib method.
137
138 /// Adds an IR module with the given ResourceTracker.
139 Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM);
140
141 /// Adds an IR module to the given JITDylib.
142 Error addIRModule(JITDylib &JD, ThreadSafeModule TSM);
143
144 /// Adds an IR module to the Main JITDylib.
146 return addIRModule(*Main, std::move(TSM));
147 }
148
149 /// Adds an object file to the given JITDylib.
150 Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr<MemoryBuffer> Obj);
151
152 /// Adds an object file to the given JITDylib.
153 Error addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj);
154
155 /// Adds an object file to the given JITDylib.
156 Error addObjectFile(std::unique_ptr<MemoryBuffer> Obj) {
157 return addObjectFile(*Main, std::move(Obj));
158 }
159
160 /// Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to
161 /// look up symbols based on their IR name use the lookup function instead).
162 Expected<ExecutorAddr> lookupLinkerMangled(JITDylib &JD,
163 SymbolStringPtr Name);
164
165 /// Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to
166 /// look up symbols based on their IR name use the lookup function instead).
168 StringRef Name) {
169 return lookupLinkerMangled(JD, ES->intern(Name));
170 }
171
172 /// Look up a symbol in the main JITDylib by the symbol's linker-mangled name
173 /// (to look up symbols based on their IR name use the lookup function
174 /// instead).
178
179 /// Look up a symbol in JITDylib JD based on its IR symbol name.
181 return lookupLinkerMangled(JD, mangle(UnmangledName));
182 }
183
184 /// Look up a symbol in the main JITDylib based on its IR symbol name.
186 return lookup(*Main, UnmangledName);
187 }
188
189 /// Set the PlatformSupport instance.
190 void setPlatformSupport(std::unique_ptr<PlatformSupport> PS) {
191 this->PS = std::move(PS);
192 }
193
194 /// Get the PlatformSupport instance.
196
197 /// Run the initializers for the given JITDylib.
199 DEBUG_WITH_TYPE("orc", {
200 dbgs() << "LLJIT running initializers for JITDylib \"" << JD.getName()
201 << "\"\n";
202 });
203 assert(PS && "PlatformSupport must be set to run initializers.");
204 return PS->initialize(JD);
205 }
206
207 /// Run the deinitializers for the given JITDylib.
209 DEBUG_WITH_TYPE("orc", {
210 dbgs() << "LLJIT running deinitializers for JITDylib \"" << JD.getName()
211 << "\"\n";
212 });
213 assert(PS && "PlatformSupport must be set to run initializers.");
214 return PS->deinitialize(JD);
215 }
216
217 /// Returns a reference to the DylibManager for the target process.
219 assert(DylibMgr && "No DylibMgr set");
220 return *DylibMgr;
221 }
222
223 /// Returns a reference to the ObjLinkingLayer
225
226 /// Returns a reference to the object transform layer.
228
229 /// Returns a reference to the IR transform layer.
231
232 /// Returns a reference to the IR compile layer.
234
235 /// Returns a linker-mangled version of UnmangledName.
236 std::string mangle(StringRef UnmangledName) const;
237
238 /// Returns an interned, linker-mangled version of UnmangledName.
240 return ES->intern(mangle(UnmangledName));
241 }
242
243protected:
245 createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES);
246
248 createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB);
249
250 /// Create an LLJIT instance with a single compile thread.
251 LLJIT(LLJITBuilderState &S, Error &Err);
252
253 Error applyDataLayout(Module &M);
254
255 std::unique_ptr<ExecutionSession> ES;
256 std::unique_ptr<PlatformSupport> PS;
257 std::unique_ptr<DylibManager> DylibMgr;
258
260 JITDylib *Platform = nullptr;
261 JITDylib *Main = nullptr;
262
264
267
268 std::unique_ptr<ObjectLayer> ObjLinkingLayer;
269 std::unique_ptr<ObjectTransformLayer> ObjTransformLayer;
270 std::unique_ptr<IRCompileLayer> CompileLayer;
271 std::unique_ptr<IRTransformLayer> TransformLayer;
272 std::unique_ptr<IRTransformLayer> InitHelperTransformLayer;
273};
274
275/// An extended version of LLJIT that supports lazy function-at-a-time
276/// compilation of LLVM IR.
277class LLLazyJIT : public LLJIT {
278 template <typename, typename, typename> friend class LLJITBuilderSetters;
279
280public:
281
282 /// Sets the partition function.
284 IPLayer->setPartitionFunction(std::move(Partition));
285 }
286
287 /// Returns a reference to the on-demand layer.
289
290 /// Add a module to be lazily compiled to JITDylib JD.
292
293 /// Add a module to be lazily compiled to the main JITDylib.
295 return addLazyIRModule(*Main, std::move(M));
296 }
297
298private:
299
300 // Create a single-threaded LLLazyJIT instance.
302
303 std::unique_ptr<LazyCallThroughManager> LCTMgr;
304 std::unique_ptr<IRPartitionLayer> IPLayer;
305 std::unique_ptr<CompileOnDemandLayer> CODLayer;
306};
307
309public:
311 std::function<Expected<std::unique_ptr<ObjectLayer>>(ExecutionSession &)>;
312
314 std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(
316
319
321
322 using NotifyCreatedFunction = std::function<Error(LLJIT &)>;
323
324 std::unique_ptr<ExecutorProcessControl> EPC;
325 std::unique_ptr<ExecutionSession> ES;
326 std::optional<JITTargetMachineBuilder> JTMB;
327 std::optional<DataLayout> DL;
335 unsigned NumCompileThreads = 0;
336 std::optional<bool> SupportConcurrentCompilation;
337
338 /// Called prior to JIT class construcion to fix up defaults.
340};
341
342template <typename JITType, typename SetterImpl, typename State>
344public:
345 /// Set an ExecutorProcessControl for this instance.
346 /// This should not be called if ExecutionSession has already been set.
347 SetterImpl &
348 setExecutorProcessControl(std::unique_ptr<ExecutorProcessControl> EPC) {
349 assert(
350 !impl().ES &&
351 "setExecutorProcessControl should not be called if an ExecutionSession "
352 "has already been set");
353 impl().EPC = std::move(EPC);
354 return impl();
355 }
356
357 /// Set an ExecutionSession for this instance.
358 SetterImpl &setExecutionSession(std::unique_ptr<ExecutionSession> ES) {
359 assert(
360 !impl().EPC &&
361 "setExecutionSession should not be called if an ExecutorProcessControl "
362 "object has already been set");
363 impl().ES = std::move(ES);
364 return impl();
365 }
366
367 /// Set the JITTargetMachineBuilder for this instance.
368 ///
369 /// If this method is not called, JITTargetMachineBuilder::detectHost will be
370 /// used to construct a default target machine builder for the host platform.
372 impl().JTMB = std::move(JTMB);
373 return impl();
374 }
375
376 /// Return a reference to the JITTargetMachineBuilder.
377 ///
378 std::optional<JITTargetMachineBuilder> &getJITTargetMachineBuilder() {
379 return impl().JTMB;
380 }
381
382 /// Set a DataLayout for this instance. If no data layout is specified then
383 /// the target's default data layout will be used.
384 SetterImpl &setDataLayout(std::optional<DataLayout> DL) {
385 impl().DL = std::move(DL);
386 return impl();
387 }
388
389 /// The LinkProcessSymbolsDyDefault flag determines whether the "Process"
390 /// JITDylib will be added to the default link order at LLJIT construction
391 /// time. If true, the Process JITDylib will be added as the last item in the
392 /// default link order. If false (or if the Process JITDylib is disabled via
393 /// setProcessSymbolsJITDylibSetup) then the Process JITDylib will not appear
394 /// in the default link order.
395 SetterImpl &setLinkProcessSymbolsByDefault(bool LinkProcessSymbolsByDefault) {
396 impl().LinkProcessSymbolsByDefault = LinkProcessSymbolsByDefault;
397 return impl();
398 }
399
400 /// Set a setup function for the process symbols dylib. If not provided,
401 /// but LinkProcessSymbolsJITDylibByDefault is true, then the process-symbols
402 /// JITDylib will be configured with a DynamicLibrarySearchGenerator with a
403 /// default symbol filter.
406 SetupProcessSymbolsJITDylib) {
407 impl().SetupProcessSymbolsJITDylib = std::move(SetupProcessSymbolsJITDylib);
408 return impl();
409 }
410
411 /// Set an ObjectLinkingLayer creation function.
412 ///
413 /// If this method is not called, a default creation function will be used
414 /// that will construct an RTDyldObjectLinkingLayer.
416 LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer) {
417 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);
418 return impl();
419 }
420
421 /// Set a CompileFunctionCreator.
422 ///
423 /// If this method is not called, a default creation function wil be used
424 /// that will construct a basic IR compile function that is compatible with
425 /// the selected number of threads (SimpleCompiler for '0' compile threads,
426 /// ConcurrentIRCompiler otherwise).
428 LLJITBuilderState::CompileFunctionCreator CreateCompileFunction) {
429 impl().CreateCompileFunction = std::move(CreateCompileFunction);
430 return impl();
431 }
432
433 /// Set a setup function to be run just before the PlatformSetupFunction is
434 /// run.
435 ///
436 /// This can be used to customize the LLJIT instance before the platform is
437 /// set up. E.g. By installing a debugger support plugin before the platform
438 /// is set up (when the ORC runtime is loaded) we enable debugging of the
439 /// runtime itself.
440 SetterImpl &
442 impl().PrePlatformSetup = std::move(PrePlatformSetup);
443 return impl();
444 }
445
446 /// Set up an PlatformSetupFunction.
447 ///
448 /// If this method is not called then setUpGenericLLVMIRPlatform
449 /// will be used to configure the JIT's platform support.
450 SetterImpl &
452 impl().SetUpPlatform = std::move(SetUpPlatform);
453 return impl();
454 }
455
456 /// Set up a callback after successful construction of the JIT.
457 ///
458 /// This is useful to attach generators to JITDylibs or inject initial symbol
459 /// definitions.
460 SetterImpl &
462 impl().NotifyCreated = std::move(Callback);
463 return impl();
464 }
465
466 /// Set the number of compile threads to use.
467 ///
468 /// If set to zero, compilation will be performed on the execution thread when
469 /// JITing in-process. If set to any other number N, a thread pool of N
470 /// threads will be created for compilation.
471 ///
472 /// If this method is not called, behavior will be as if it were called with
473 /// a zero argument.
474 ///
475 /// This setting should not be used if a custom ExecutionSession or
476 /// ExecutorProcessControl object is set: in those cases a custom
477 /// TaskDispatcher should be used instead.
478 SetterImpl &setNumCompileThreads(unsigned NumCompileThreads) {
479 impl().NumCompileThreads = NumCompileThreads;
480 return impl();
481 }
482
483 /// If set, this forces LLJIT concurrent compilation support to be either on
484 /// or off. This controls the selection of compile function (concurrent vs
485 /// single threaded) and whether or not sub-modules are cloned to new
486 /// contexts for lazy emission.
487 ///
488 /// If not explicitly set then concurrency support will be turned on if
489 /// NumCompileThreads is set to a non-zero value, or if a custom
490 /// ExecutionSession or ExecutorProcessControl instance is provided.
492 std::optional<bool> SupportConcurrentCompilation) {
493 impl().SupportConcurrentCompilation = SupportConcurrentCompilation;
494 return impl();
495 }
496
497 /// Create an instance of the JIT.
499 if (auto Err = impl().prepareForConstruction())
500 return std::move(Err);
501
502 Error Err = Error::success();
503 std::unique_ptr<JITType> J(new JITType(impl(), Err));
504 if (Err)
505 return std::move(Err);
506
507 if (impl().NotifyCreated)
508 if (Error Err = impl().NotifyCreated(*J))
509 return std::move(Err);
510
511 return std::move(J);
512 }
513
514protected:
515 SetterImpl &impl() { return static_cast<SetterImpl &>(*this); }
516};
517
518/// Constructs LLJIT instances.
520 : public LLJITBuilderState,
521 public LLJITBuilderSetters<LLJIT, LLJITBuilder, LLJITBuilderState> {};
522
524 friend class LLLazyJIT;
525
526public:
528 std::function<std::unique_ptr<IndirectStubsManager>()>;
529
532 std::unique_ptr<LazyCallThroughManager> LCTMgr;
534
536};
537
538template <typename JITType, typename SetterImpl, typename State>
540 : public LLJITBuilderSetters<JITType, SetterImpl, State> {
541public:
542 /// Set the address in the target address to call if a lazy compile fails.
543 ///
544 /// If this method is not called then the value will default to 0.
546 this->impl().LazyCompileFailureAddr = Addr;
547 return this->impl();
548 }
549
550 /// Set the lazy-callthrough manager.
551 ///
552 /// If this method is not called then a default, in-process lazy callthrough
553 /// manager for the host platform will be used.
554 SetterImpl &
555 setLazyCallthroughManager(std::unique_ptr<LazyCallThroughManager> LCTMgr) {
556 this->impl().LCTMgr = std::move(LCTMgr);
557 return this->impl();
558 }
559
560 /// Set the IndirectStubsManager builder function.
561 ///
562 /// If this method is not called then a default, in-process
563 /// IndirectStubsManager builder for the host platform will be used.
566 this->impl().ISMBuilder = std::move(ISMBuilder);
567 return this->impl();
568 }
569};
570
571/// Constructs LLLazyJIT instances.
573 : public LLLazyJITBuilderState,
574 public LLLazyJITBuilderSetters<LLLazyJIT, LLLazyJITBuilder,
575 LLLazyJITBuilderState> {};
576
577/// Configure the LLJIT instance to use orc runtime support. This overload
578/// assumes that the client has manually configured a Platform object.
580
581/// Configure the LLJIT instance to use the ORC runtime and the detected
582/// native target for the executor.
584public:
585 /// Set up using path to Orc runtime.
586 ExecutorNativePlatform(std::string OrcRuntimePath)
587 : OrcRuntime(std::move(OrcRuntimePath)) {}
588
589 /// Set up using the given memory buffer.
590 ExecutorNativePlatform(std::unique_ptr<MemoryBuffer> OrcRuntimeMB)
591 : OrcRuntime(std::move(OrcRuntimeMB)) {}
592
593 // TODO: add compiler-rt.
594
595 /// Add a path to the VC runtime.
596 ExecutorNativePlatform &addVCRuntime(std::string VCRuntimePath,
597 bool StaticVCRuntime) {
598 VCRuntime = {std::move(VCRuntimePath), StaticVCRuntime};
599 return *this;
600 }
601
603
604private:
605 std::variant<std::string, std::unique_ptr<MemoryBuffer>> OrcRuntime;
606 std::optional<std::pair<std::string, bool>> VCRuntime;
607};
608
609/// Configure the LLJIT instance to scrape modules for llvm.global_ctors and
610/// llvm.global_dtors variables and (if present) build initialization and
611/// deinitialization functions. Platform specific initialization configurations
612/// should be preferred where available.
614
615/// Configure the LLJIT instance to disable platform support explicitly. This is
616/// useful in two cases: for platforms that don't have such requirements and for
617/// platforms, that we have no explicit support yet and that don't work well
618/// with the generic IR platform.
620
621/// A Platform-support class that implements initialize / deinitialize by
622/// forwarding to ORC runtime dlopen / dlclose operations.
624public:
626 Error initialize(orc::JITDylib &JD) override;
627 Error deinitialize(orc::JITDylib &JD) override;
628
629private:
630 orc::LLJIT &J;
632 SmallPtrSet<JITDylib const *, 8> InitializedDylib;
633};
634
635} // End namespace orc
636} // End namespace llvm
637
638#endif // LLVM_EXECUTIONENGINE_ORC_LLJIT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:213
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
#define T
This file defines the SmallSet class.
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition Debug.h:72
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
An ExecutionSession represents a running JIT program.
Definition Core.h:1355
Represents an address in the executor process.
ExecutorNativePlatform & addVCRuntime(std::string VCRuntimePath, bool StaticVCRuntime)
Add a path to the VC runtime.
Definition LLJIT.h:596
ExecutorNativePlatform(std::unique_ptr< MemoryBuffer > OrcRuntimeMB)
Set up using the given memory buffer.
Definition LLJIT.h:590
ExecutorNativePlatform(std::string OrcRuntimePath)
Set up using path to Orc runtime.
Definition LLJIT.h:586
LLVM_ABI Expected< JITDylibSP > operator()(LLJIT &J)
Definition LLJIT.cpp:1133
ExecutorProcessControl supports interaction with a JIT target process.
std::function< std::optional< GlobalValueSet >(GlobalValueSet Requested)> PartitionFunction
Partitioning function.
A layer that applies a transform to emitted modules.
unique_function< Expected< ThreadSafeModule >( ThreadSafeModule, MaterializationResponsibility &R)> TransformFunction
Represents a JIT'd dynamic library.
Definition Core.h:919
A utility class for building TargetMachines for JITs.
SetterImpl & setLinkProcessSymbolsByDefault(bool LinkProcessSymbolsByDefault)
The LinkProcessSymbolsDyDefault flag determines whether the "Process" JITDylib will be added to the d...
Definition LLJIT.h:395
SetterImpl & setNotifyCreatedCallback(LLJITBuilderState::NotifyCreatedFunction Callback)
Set up a callback after successful construction of the JIT.
Definition LLJIT.h:461
std::optional< JITTargetMachineBuilder > & getJITTargetMachineBuilder()
Return a reference to the JITTargetMachineBuilder.
Definition LLJIT.h:378
SetterImpl & setPrePlatformSetup(unique_function< Error(LLJIT &)> PrePlatformSetup)
Set a setup function to be run just before the PlatformSetupFunction is run.
Definition LLJIT.h:441
SetterImpl & setCompileFunctionCreator(LLJITBuilderState::CompileFunctionCreator CreateCompileFunction)
Set a CompileFunctionCreator.
Definition LLJIT.h:427
SetterImpl & setNumCompileThreads(unsigned NumCompileThreads)
Set the number of compile threads to use.
Definition LLJIT.h:478
SetterImpl & setDataLayout(std::optional< DataLayout > DL)
Set a DataLayout for this instance.
Definition LLJIT.h:384
SetterImpl & setJITTargetMachineBuilder(JITTargetMachineBuilder JTMB)
Set the JITTargetMachineBuilder for this instance.
Definition LLJIT.h:371
SetterImpl & setExecutorProcessControl(std::unique_ptr< ExecutorProcessControl > EPC)
Set an ExecutorProcessControl for this instance.
Definition LLJIT.h:348
SetterImpl & setObjectLinkingLayerCreator(LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer)
Set an ObjectLinkingLayer creation function.
Definition LLJIT.h:415
SetterImpl & setPlatformSetUp(LLJITBuilderState::PlatformSetupFunction SetUpPlatform)
Set up an PlatformSetupFunction.
Definition LLJIT.h:451
Expected< std::unique_ptr< JITType > > create()
Create an instance of the JIT.
Definition LLJIT.h:498
SetterImpl & setExecutionSession(std::unique_ptr< ExecutionSession > ES)
Set an ExecutionSession for this instance.
Definition LLJIT.h:358
SetterImpl & setSupportConcurrentCompilation(std::optional< bool > SupportConcurrentCompilation)
If set, this forces LLJIT concurrent compilation support to be either on or off.
Definition LLJIT.h:491
SetterImpl & setProcessSymbolsJITDylibSetup(LLJITBuilderState::ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib)
Set a setup function for the process symbols dylib.
Definition LLJIT.h:404
LLVM_ABI Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
Definition LLJIT.cpp:679
ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib
Definition LLJIT.h:329
ObjectLinkingLayerCreator CreateObjectLinkingLayer
Definition LLJIT.h:330
std::function< Error(LLJIT &)> NotifyCreatedFunction
Definition LLJIT.h:322
std::unique_ptr< ExecutionSession > ES
Definition LLJIT.h:325
unique_function< Error(LLJIT &)> PrePlatformSetup
Definition LLJIT.h:332
CompileFunctionCreator CreateCompileFunction
Definition LLJIT.h:331
std::optional< bool > SupportConcurrentCompilation
Definition LLJIT.h:336
std::unique_ptr< ExecutorProcessControl > EPC
Definition LLJIT.h:324
std::optional< DataLayout > DL
Definition LLJIT.h:327
std::optional< JITTargetMachineBuilder > JTMB
Definition LLJIT.h:326
unique_function< Expected< JITDylibSP >(LLJIT &J)> PlatformSetupFunction
Definition LLJIT.h:320
std::function< Expected< std::unique_ptr< ObjectLayer > >(ExecutionSession &)> ObjectLinkingLayerCreator
Definition LLJIT.h:310
PlatformSetupFunction SetUpPlatform
Definition LLJIT.h:333
NotifyCreatedFunction NotifyCreated
Definition LLJIT.h:334
unique_function< Expected< JITDylibSP >(LLJIT &J)> ProcessSymbolsJITDylibSetupFunction
Definition LLJIT.h:317
std::function< Expected< std::unique_ptr< IRCompileLayer::IRCompiler > >( JITTargetMachineBuilder JTMB)> CompileFunctionCreator
Definition LLJIT.h:313
Constructs LLJIT instances.
Definition LLJIT.h:521
Initializer support for LLJIT.
Definition LLJIT.h:50
virtual Error deinitialize(JITDylib &JD)=0
virtual Error initialize(JITDylib &JD)=0
static void setInitTransform(LLJIT &J, IRTransformLayer::TransformFunction T)
Definition LLJIT.cpp:672
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
Definition LLJIT.h:43
void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)
Set the PlatformSupport instance.
Definition LLJIT.h:190
std::unique_ptr< ExecutionSession > ES
Definition LLJIT.h:255
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
Definition LLJIT.cpp:995
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Definition LLJIT.cpp:924
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
Definition LLJIT.h:77
JITDylibSearchOrder DefaultLinks
Definition LLJIT.h:263
const DataLayout & getDataLayout() const
Returns a reference to the DataLayout for this instance.
Definition LLJIT.h:74
Error initialize(JITDylib &JD)
Run the initializers for the given JITDylib.
Definition LLJIT.h:198
Error addIRModule(ThreadSafeModule TSM)
Adds an IR module to the Main JITDylib.
Definition LLJIT.h:145
ObjectLayer & getObjLinkingLayer()
Returns a reference to the ObjLinkingLayer.
Definition LLJIT.h:224
Expected< ExecutorAddr > lookupLinkerMangled(JITDylib &JD, StringRef Name)
Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on thei...
Definition LLJIT.h:167
IRCompileLayer & getIRCompileLayer()
Returns a reference to the IR compile layer.
Definition LLJIT.h:233
std::unique_ptr< ObjectTransformLayer > ObjTransformLayer
Definition LLJIT.h:269
IRTransformLayer & getIRTransformLayer()
Returns a reference to the IR transform layer.
Definition LLJIT.h:230
std::string mangle(StringRef UnmangledName) const
Returns a linker-mangled version of UnmangledName.
Definition LLJIT.cpp:1085
JITDylib * Main
Definition LLJIT.h:261
Expected< ExecutorAddr > lookup(JITDylib &JD, StringRef UnmangledName)
Look up a symbol in JITDylib JD based on its IR symbol name.
Definition LLJIT.h:180
std::unique_ptr< IRTransformLayer > InitHelperTransformLayer
Definition LLJIT.h:272
Error deinitialize(JITDylib &JD)
Run the deinitializers for the given JITDylib.
Definition LLJIT.h:208
std::unique_ptr< IRCompileLayer > CompileLayer
Definition LLJIT.h:270
Expected< ExecutorAddr > lookup(StringRef UnmangledName)
Look up a symbol in the main JITDylib based on its IR symbol name.
Definition LLJIT.h:185
const Triple & getTargetTriple() const
Returns a reference to the triple for this instance.
Definition LLJIT.h:71
Expected< ExecutorAddr > lookupLinkerMangled(JITDylib &JD, SymbolStringPtr Name)
Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on thei...
Definition LLJIT.cpp:935
PlatformSupport * getPlatformSupport()
Get the PlatformSupport instance.
Definition LLJIT.h:195
JITDylib * ProcessSymbols
Definition LLJIT.h:259
JITDylib * Platform
Definition LLJIT.h:260
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition LLJIT.h:68
std::unique_ptr< IRTransformLayer > TransformLayer
Definition LLJIT.h:271
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Definition LLJIT.h:239
DataLayout DL
Definition LLJIT.h:265
Error addObjectFile(std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Definition LLJIT.h:156
std::unique_ptr< DylibManager > DylibMgr
Definition LLJIT.h:257
std::unique_ptr< ObjectLayer > ObjLinkingLayer
Definition LLJIT.h:268
std::unique_ptr< PlatformSupport > PS
Definition LLJIT.h:256
JITDylibSearchOrder defaultLinkOrder()
Returns the default link order for this LLJIT instance.
Definition LLJIT.h:136
LLVM_ABI friend Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition LLJIT.cpp:1215
JITDylib * getJITDylibByName(StringRef Name)
Returns the JITDylib with the given name, or nullptr if no JITDylib with that name exists.
Definition LLJIT.h:95
ObjectTransformLayer & getObjTransformLayer()
Returns a reference to the object transform layer.
Definition LLJIT.h:227
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
Definition LLJIT.cpp:910
friend class LLJITBuilderSetters
Definition LLJIT.h:44
DylibManager & getDylibMgr()
Returns a reference to the DylibManager for the target process.
Definition LLJIT.h:218
Expected< ExecutorAddr > lookupLinkerMangled(StringRef Name)
Look up a symbol in the main JITDylib by the symbol's linker-mangled name (to look up symbols based o...
Definition LLJIT.h:175
SetterImpl & setLazyCompileFailureAddr(ExecutorAddr Addr)
Set the address in the target address to call if a lazy compile fails.
Definition LLJIT.h:545
SetterImpl & setLazyCallthroughManager(std::unique_ptr< LazyCallThroughManager > LCTMgr)
Set the lazy-callthrough manager.
Definition LLJIT.h:555
SetterImpl & setIndirectStubsManagerBuilder(LLLazyJITBuilderState::IndirectStubsManagerBuilderFunction ISMBuilder)
Set the IndirectStubsManager builder function.
Definition LLJIT.h:564
ExecutorAddr LazyCompileFailureAddr
Definition LLJIT.h:531
std::function< std::unique_ptr< IndirectStubsManager >()> IndirectStubsManagerBuilderFunction
Definition LLJIT.h:527
std::unique_ptr< LazyCallThroughManager > LCTMgr
Definition LLJIT.h:532
LLVM_ABI Error prepareForConstruction()
Definition LLJIT.cpp:1282
IndirectStubsManagerBuilderFunction ISMBuilder
Definition LLJIT.h:533
Constructs LLLazyJIT instances.
Definition LLJIT.h:575
An extended version of LLJIT that supports lazy function-at-a-time compilation of LLVM IR.
Definition LLJIT.h:277
void setPartitionFunction(IRPartitionLayer::PartitionFunction Partition)
Sets the partition function.
Definition LLJIT.h:283
Error addLazyIRModule(ThreadSafeModule M)
Add a module to be lazily compiled to the main JITDylib.
Definition LLJIT.h:294
CompileOnDemandLayer & getCompileOnDemandLayer()
Returns a reference to the on-demand layer.
Definition LLJIT.h:288
friend class LLJITBuilderSetters
Definition LLJIT.h:278
LLVM_ABI Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
Definition LLJIT.cpp:1289
ORCPlatformSupport(orc::LLJIT &J)
Definition LLJIT.h:625
Interface for Layers that accept object files.
Definition Layer.h:134
Pointer to a pooled string representing a symbol name.
An LLVM Module together with a shared ThreadSafeContext.
unique_function is a type-erasing functor similar to std::function.
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition Core.h:177
IntrusiveRefCntPtr< JITDylib > JITDylibSP
Definition Core.h:57
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
Definition Core.h:56
LLVM_ABI Expected< JITDylibSP > setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
Definition LLJIT.cpp:1275
LLVM_ABI Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition LLJIT.cpp:1215
LLVM_ABI Error setUpOrcPlatformManually(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
Definition LLJIT.cpp:1108
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
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:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870