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