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,
247
249 createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB);
250
251 /// Create an LLJIT instance with a single compile thread.
252 LLJIT(LLJITBuilderState &S, Error &Err);
253
254 Error applyDataLayout(Module &M);
255
256 std::unique_ptr<ExecutionSession> ES;
257 std::unique_ptr<PlatformSupport> PS;
258 std::unique_ptr<DylibManager> DylibMgr;
259
261 JITDylib *Platform = nullptr;
262 JITDylib *Main = nullptr;
263
265
268
269 std::unique_ptr<ObjectLayer> ObjLinkingLayer;
270 std::unique_ptr<ObjectTransformLayer> ObjTransformLayer;
271 std::unique_ptr<IRCompileLayer> CompileLayer;
272 std::unique_ptr<IRTransformLayer> TransformLayer;
273 std::unique_ptr<IRTransformLayer> InitHelperTransformLayer;
274};
275
276/// An extended version of LLJIT that supports lazy function-at-a-time
277/// compilation of LLVM IR.
278class LLLazyJIT : public LLJIT {
279 template <typename, typename, typename> friend class LLJITBuilderSetters;
280
281public:
282
283 /// Sets the partition function.
285 IPLayer->setPartitionFunction(std::move(Partition));
286 }
287
288 /// Returns a reference to the on-demand layer.
290
291 /// Add a module to be lazily compiled to JITDylib JD.
293
294 /// Add a module to be lazily compiled to the main JITDylib.
296 return addLazyIRModule(*Main, std::move(M));
297 }
298
299private:
300
301 // Create a single-threaded LLLazyJIT instance.
303
304 std::unique_ptr<LazyCallThroughManager> LCTMgr;
305 std::unique_ptr<IRPartitionLayer> IPLayer;
306 std::unique_ptr<CompileOnDemandLayer> CODLayer;
307};
308
310public:
312 std::function<Expected<std::unique_ptr<ObjectLayer>>(
314
316 std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(
318
321
323
324 using NotifyCreatedFunction = std::function<Error(LLJIT &)>;
325
326 std::unique_ptr<ExecutorProcessControl> EPC;
327 std::unique_ptr<ExecutionSession> ES;
328 std::optional<JITTargetMachineBuilder> JTMB;
329 std::optional<DataLayout> DL;
337 unsigned NumCompileThreads = 0;
338 std::optional<bool> SupportConcurrentCompilation;
339
340 /// Called prior to JIT class construcion to fix up defaults.
342};
343
344template <typename JITType, typename SetterImpl, typename State>
346public:
347 /// Set an ExecutorProcessControl for this instance.
348 /// This should not be called if ExecutionSession has already been set.
349 SetterImpl &
350 setExecutorProcessControl(std::unique_ptr<ExecutorProcessControl> EPC) {
351 assert(
352 !impl().ES &&
353 "setExecutorProcessControl should not be called if an ExecutionSession "
354 "has already been set");
355 impl().EPC = std::move(EPC);
356 return impl();
357 }
358
359 /// Set an ExecutionSession for this instance.
360 SetterImpl &setExecutionSession(std::unique_ptr<ExecutionSession> ES) {
361 assert(
362 !impl().EPC &&
363 "setExecutionSession should not be called if an ExecutorProcessControl "
364 "object has already been set");
365 impl().ES = std::move(ES);
366 return impl();
367 }
368
369 /// Set the JITTargetMachineBuilder for this instance.
370 ///
371 /// If this method is not called, JITTargetMachineBuilder::detectHost will be
372 /// used to construct a default target machine builder for the host platform.
374 impl().JTMB = std::move(JTMB);
375 return impl();
376 }
377
378 /// Return a reference to the JITTargetMachineBuilder.
379 ///
380 std::optional<JITTargetMachineBuilder> &getJITTargetMachineBuilder() {
381 return impl().JTMB;
382 }
383
384 /// Set a DataLayout for this instance. If no data layout is specified then
385 /// the target's default data layout will be used.
386 SetterImpl &setDataLayout(std::optional<DataLayout> DL) {
387 impl().DL = std::move(DL);
388 return impl();
389 }
390
391 /// The LinkProcessSymbolsDyDefault flag determines whether the "Process"
392 /// JITDylib will be added to the default link order at LLJIT construction
393 /// time. If true, the Process JITDylib will be added as the last item in the
394 /// default link order. If false (or if the Process JITDylib is disabled via
395 /// setProcessSymbolsJITDylibSetup) then the Process JITDylib will not appear
396 /// in the default link order.
397 SetterImpl &setLinkProcessSymbolsByDefault(bool LinkProcessSymbolsByDefault) {
398 impl().LinkProcessSymbolsByDefault = LinkProcessSymbolsByDefault;
399 return impl();
400 }
401
402 /// Set a setup function for the process symbols dylib. If not provided,
403 /// but LinkProcessSymbolsJITDylibByDefault is true, then the process-symbols
404 /// JITDylib will be configured with a DynamicLibrarySearchGenerator with a
405 /// default symbol filter.
408 SetupProcessSymbolsJITDylib) {
409 impl().SetupProcessSymbolsJITDylib = std::move(SetupProcessSymbolsJITDylib);
410 return impl();
411 }
412
413 /// Set an ObjectLinkingLayer creation function.
414 ///
415 /// If this method is not called, a default creation function will be used
416 /// that will construct an RTDyldObjectLinkingLayer.
418 LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer) {
419 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);
420 return impl();
421 }
422
423 /// Set a CompileFunctionCreator.
424 ///
425 /// If this method is not called, a default creation function wil be used
426 /// that will construct a basic IR compile function that is compatible with
427 /// the selected number of threads (SimpleCompiler for '0' compile threads,
428 /// ConcurrentIRCompiler otherwise).
430 LLJITBuilderState::CompileFunctionCreator CreateCompileFunction) {
431 impl().CreateCompileFunction = std::move(CreateCompileFunction);
432 return impl();
433 }
434
435 /// Set a setup function to be run just before the PlatformSetupFunction is
436 /// run.
437 ///
438 /// This can be used to customize the LLJIT instance before the platform is
439 /// set up. E.g. By installing a debugger support plugin before the platform
440 /// is set up (when the ORC runtime is loaded) we enable debugging of the
441 /// runtime itself.
442 SetterImpl &
444 impl().PrePlatformSetup = std::move(PrePlatformSetup);
445 return impl();
446 }
447
448 /// Set up an PlatformSetupFunction.
449 ///
450 /// If this method is not called then setUpGenericLLVMIRPlatform
451 /// will be used to configure the JIT's platform support.
452 SetterImpl &
454 impl().SetUpPlatform = std::move(SetUpPlatform);
455 return impl();
456 }
457
458 /// Set up a callback after successful construction of the JIT.
459 ///
460 /// This is useful to attach generators to JITDylibs or inject initial symbol
461 /// definitions.
462 SetterImpl &
464 impl().NotifyCreated = std::move(Callback);
465 return impl();
466 }
467
468 /// Set the number of compile threads to use.
469 ///
470 /// If set to zero, compilation will be performed on the execution thread when
471 /// JITing in-process. If set to any other number N, a thread pool of N
472 /// threads will be created for compilation.
473 ///
474 /// If this method is not called, behavior will be as if it were called with
475 /// a zero argument.
476 ///
477 /// This setting should not be used if a custom ExecutionSession or
478 /// ExecutorProcessControl object is set: in those cases a custom
479 /// TaskDispatcher should be used instead.
480 SetterImpl &setNumCompileThreads(unsigned NumCompileThreads) {
481 impl().NumCompileThreads = NumCompileThreads;
482 return impl();
483 }
484
485 /// If set, this forces LLJIT concurrent compilation support to be either on
486 /// or off. This controls the selection of compile function (concurrent vs
487 /// single threaded) and whether or not sub-modules are cloned to new
488 /// contexts for lazy emission.
489 ///
490 /// If not explicitly set then concurrency support will be turned on if
491 /// NumCompileThreads is set to a non-zero value, or if a custom
492 /// ExecutionSession or ExecutorProcessControl instance is provided.
494 std::optional<bool> SupportConcurrentCompilation) {
495 impl().SupportConcurrentCompilation = SupportConcurrentCompilation;
496 return impl();
497 }
498
499 /// Create an instance of the JIT.
501 if (auto Err = impl().prepareForConstruction())
502 return std::move(Err);
503
504 Error Err = Error::success();
505 std::unique_ptr<JITType> J(new JITType(impl(), Err));
506 if (Err)
507 return std::move(Err);
508
509 if (impl().NotifyCreated)
510 if (Error Err = impl().NotifyCreated(*J))
511 return std::move(Err);
512
513 return std::move(J);
514 }
515
516protected:
517 SetterImpl &impl() { return static_cast<SetterImpl &>(*this); }
518};
519
520/// Constructs LLJIT instances.
522 : public LLJITBuilderState,
523 public LLJITBuilderSetters<LLJIT, LLJITBuilder, LLJITBuilderState> {};
524
526 friend class LLLazyJIT;
527
528public:
530 std::function<std::unique_ptr<IndirectStubsManager>()>;
531
534 std::unique_ptr<LazyCallThroughManager> LCTMgr;
536
538};
539
540template <typename JITType, typename SetterImpl, typename State>
542 : public LLJITBuilderSetters<JITType, SetterImpl, State> {
543public:
544 /// Set the address in the target address to call if a lazy compile fails.
545 ///
546 /// If this method is not called then the value will default to 0.
548 this->impl().LazyCompileFailureAddr = Addr;
549 return this->impl();
550 }
551
552 /// Set the lazy-callthrough manager.
553 ///
554 /// If this method is not called then a default, in-process lazy callthrough
555 /// manager for the host platform will be used.
556 SetterImpl &
557 setLazyCallthroughManager(std::unique_ptr<LazyCallThroughManager> LCTMgr) {
558 this->impl().LCTMgr = std::move(LCTMgr);
559 return this->impl();
560 }
561
562 /// Set the IndirectStubsManager builder function.
563 ///
564 /// If this method is not called then a default, in-process
565 /// IndirectStubsManager builder for the host platform will be used.
568 this->impl().ISMBuilder = std::move(ISMBuilder);
569 return this->impl();
570 }
571};
572
573/// Constructs LLLazyJIT instances.
575 : public LLLazyJITBuilderState,
576 public LLLazyJITBuilderSetters<LLLazyJIT, LLLazyJITBuilder,
577 LLLazyJITBuilderState> {};
578
579/// Configure the LLJIT instance to use orc runtime support. This overload
580/// assumes that the client has manually configured a Platform object.
582
583/// Configure the LLJIT instance to use the ORC runtime and the detected
584/// native target for the executor.
586public:
587 /// Set up using path to Orc runtime.
588 ExecutorNativePlatform(std::string OrcRuntimePath)
589 : OrcRuntime(std::move(OrcRuntimePath)) {}
590
591 /// Set up using the given memory buffer.
592 ExecutorNativePlatform(std::unique_ptr<MemoryBuffer> OrcRuntimeMB)
593 : OrcRuntime(std::move(OrcRuntimeMB)) {}
594
595 // TODO: add compiler-rt.
596
597 /// Add a path to the VC runtime.
598 ExecutorNativePlatform &addVCRuntime(std::string VCRuntimePath,
599 bool StaticVCRuntime) {
600 VCRuntime = {std::move(VCRuntimePath), StaticVCRuntime};
601 return *this;
602 }
603
605
606private:
607 std::variant<std::string, std::unique_ptr<MemoryBuffer>> OrcRuntime;
608 std::optional<std::pair<std::string, bool>> VCRuntime;
609};
610
611/// Configure the LLJIT instance to scrape modules for llvm.global_ctors and
612/// llvm.global_dtors variables and (if present) build initialization and
613/// deinitialization functions. Platform specific initialization configurations
614/// should be preferred where available.
616
617/// Configure the LLJIT instance to disable platform support explicitly. This is
618/// useful in two cases: for platforms that don't have such requirements and for
619/// platforms, that we have no explicit support yet and that don't work well
620/// with the generic IR platform.
622
623/// A Platform-support class that implements initialize / deinitialize by
624/// forwarding to ORC runtime dlopen / dlclose operations.
626public:
628 Error initialize(orc::JITDylib &JD) override;
629 Error deinitialize(orc::JITDylib &JD) override;
630
631private:
632 orc::LLJIT &J;
634 SmallPtrSet<JITDylib const *, 8> InitializedDylib;
635};
636
637} // End namespace orc
638} // End namespace llvm
639
640#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, GsymDataExtractor &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:598
ExecutorNativePlatform(std::unique_ptr< MemoryBuffer > OrcRuntimeMB)
Set up using the given memory buffer.
Definition LLJIT.h:592
ExecutorNativePlatform(std::string OrcRuntimePath)
Set up using path to Orc runtime.
Definition LLJIT.h:588
LLVM_ABI Expected< JITDylibSP > operator()(LLJIT &J)
Definition LLJIT.cpp:1136
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:397
SetterImpl & setNotifyCreatedCallback(LLJITBuilderState::NotifyCreatedFunction Callback)
Set up a callback after successful construction of the JIT.
Definition LLJIT.h:463
std::optional< JITTargetMachineBuilder > & getJITTargetMachineBuilder()
Return a reference to the JITTargetMachineBuilder.
Definition LLJIT.h:380
SetterImpl & setPrePlatformSetup(unique_function< Error(LLJIT &)> PrePlatformSetup)
Set a setup function to be run just before the PlatformSetupFunction is run.
Definition LLJIT.h:443
SetterImpl & setCompileFunctionCreator(LLJITBuilderState::CompileFunctionCreator CreateCompileFunction)
Set a CompileFunctionCreator.
Definition LLJIT.h:429
SetterImpl & setNumCompileThreads(unsigned NumCompileThreads)
Set the number of compile threads to use.
Definition LLJIT.h:480
SetterImpl & setDataLayout(std::optional< DataLayout > DL)
Set a DataLayout for this instance.
Definition LLJIT.h:386
SetterImpl & setJITTargetMachineBuilder(JITTargetMachineBuilder JTMB)
Set the JITTargetMachineBuilder for this instance.
Definition LLJIT.h:373
SetterImpl & setExecutorProcessControl(std::unique_ptr< ExecutorProcessControl > EPC)
Set an ExecutorProcessControl for this instance.
Definition LLJIT.h:350
SetterImpl & setObjectLinkingLayerCreator(LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer)
Set an ObjectLinkingLayer creation function.
Definition LLJIT.h:417
SetterImpl & setPlatformSetUp(LLJITBuilderState::PlatformSetupFunction SetUpPlatform)
Set up an PlatformSetupFunction.
Definition LLJIT.h:453
Expected< std::unique_ptr< JITType > > create()
Create an instance of the JIT.
Definition LLJIT.h:500
SetterImpl & setExecutionSession(std::unique_ptr< ExecutionSession > ES)
Set an ExecutionSession for this instance.
Definition LLJIT.h:360
SetterImpl & setSupportConcurrentCompilation(std::optional< bool > SupportConcurrentCompilation)
If set, this forces LLJIT concurrent compilation support to be either on or off.
Definition LLJIT.h:493
SetterImpl & setProcessSymbolsJITDylibSetup(LLJITBuilderState::ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib)
Set a setup function for the process symbols dylib.
Definition LLJIT.h:406
LLVM_ABI Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
Definition LLJIT.cpp:679
ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib
Definition LLJIT.h:331
ObjectLinkingLayerCreator CreateObjectLinkingLayer
Definition LLJIT.h:332
std::function< Error(LLJIT &)> NotifyCreatedFunction
Definition LLJIT.h:324
std::unique_ptr< ExecutionSession > ES
Definition LLJIT.h:327
unique_function< Error(LLJIT &)> PrePlatformSetup
Definition LLJIT.h:334
CompileFunctionCreator CreateCompileFunction
Definition LLJIT.h:333
std::optional< bool > SupportConcurrentCompilation
Definition LLJIT.h:338
std::function< Expected< std::unique_ptr< ObjectLayer > >( ExecutionSession &, jitlink::JITLinkMemoryManager &)> ObjectLinkingLayerCreator
Definition LLJIT.h:311
std::unique_ptr< ExecutorProcessControl > EPC
Definition LLJIT.h:326
std::optional< DataLayout > DL
Definition LLJIT.h:329
std::optional< JITTargetMachineBuilder > JTMB
Definition LLJIT.h:328
unique_function< Expected< JITDylibSP >(LLJIT &J)> PlatformSetupFunction
Definition LLJIT.h:322
PlatformSetupFunction SetUpPlatform
Definition LLJIT.h:335
NotifyCreatedFunction NotifyCreated
Definition LLJIT.h:336
unique_function< Expected< JITDylibSP >(LLJIT &J)> ProcessSymbolsJITDylibSetupFunction
Definition LLJIT.h:319
std::function< Expected< std::unique_ptr< IRCompileLayer::IRCompiler > >( JITTargetMachineBuilder JTMB)> CompileFunctionCreator
Definition LLJIT.h:315
Constructs LLJIT instances.
Definition LLJIT.h:523
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:256
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
Definition LLJIT.cpp:997
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Definition LLJIT.cpp:925
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
Definition LLJIT.h:77
JITDylibSearchOrder DefaultLinks
Definition LLJIT.h:264
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:270
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:1088
JITDylib * Main
Definition LLJIT.h:262
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:273
Error deinitialize(JITDylib &JD)
Run the deinitializers for the given JITDylib.
Definition LLJIT.h:208
std::unique_ptr< IRCompileLayer > CompileLayer
Definition LLJIT.h:271
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:936
PlatformSupport * getPlatformSupport()
Get the PlatformSupport instance.
Definition LLJIT.h:195
JITDylib * ProcessSymbols
Definition LLJIT.h:260
JITDylib * Platform
Definition LLJIT.h:261
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition LLJIT.h:68
std::unique_ptr< IRTransformLayer > TransformLayer
Definition LLJIT.h:272
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Definition LLJIT.h:239
DataLayout DL
Definition LLJIT.h:266
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:258
std::unique_ptr< ObjectLayer > ObjLinkingLayer
Definition LLJIT.h:269
std::unique_ptr< PlatformSupport > PS
Definition LLJIT.h:257
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:1218
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:911
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:547
SetterImpl & setLazyCallthroughManager(std::unique_ptr< LazyCallThroughManager > LCTMgr)
Set the lazy-callthrough manager.
Definition LLJIT.h:557
SetterImpl & setIndirectStubsManagerBuilder(LLLazyJITBuilderState::IndirectStubsManagerBuilderFunction ISMBuilder)
Set the IndirectStubsManager builder function.
Definition LLJIT.h:566
ExecutorAddr LazyCompileFailureAddr
Definition LLJIT.h:533
std::function< std::unique_ptr< IndirectStubsManager >()> IndirectStubsManagerBuilderFunction
Definition LLJIT.h:529
std::unique_ptr< LazyCallThroughManager > LCTMgr
Definition LLJIT.h:534
LLVM_ABI Error prepareForConstruction()
Definition LLJIT.cpp:1285
IndirectStubsManagerBuilderFunction ISMBuilder
Definition LLJIT.h:535
Constructs LLLazyJIT instances.
Definition LLJIT.h:577
An extended version of LLJIT that supports lazy function-at-a-time compilation of LLVM IR.
Definition LLJIT.h:278
void setPartitionFunction(IRPartitionLayer::PartitionFunction Partition)
Sets the partition function.
Definition LLJIT.h:284
Error addLazyIRModule(ThreadSafeModule M)
Add a module to be lazily compiled to the main JITDylib.
Definition LLJIT.h:295
CompileOnDemandLayer & getCompileOnDemandLayer()
Returns a reference to the on-demand layer.
Definition LLJIT.h:289
friend class LLJITBuilderSetters
Definition LLJIT.h:279
LLVM_ABI Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
Definition LLJIT.cpp:1292
ORCPlatformSupport(orc::LLJIT &J)
Definition LLJIT.h:627
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:1278
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:1218
LLVM_ABI Error setUpOrcPlatformManually(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
Definition LLJIT.cpp:1111
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