LLVM 24.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
300
301 /// Returns a reference to the on-demand layer.
303
304 /// Add a module to be lazily compiled to JITDylib JD.
306
307 /// Add a module to be lazily compiled to the main JITDylib.
309 return addLazyIRModule(*Main, std::move(M));
310 }
311
312private:
313
314 // Create a single-threaded LLLazyJIT instance.
316
317 std::unique_ptr<LazyCallThroughManager> LCTMgr;
318 std::unique_ptr<IRPartitionLayer> IPLayer;
319 std::unique_ptr<CompileOnDemandLayer> CODLayer;
320};
321
323public:
325 std::function<Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>(
327
329 std::function<Expected<std::unique_ptr<ObjectLayer>>(
331
333 std::function<Expected<std::unique_ptr<IRCompileLayer::IRCompiler>>(
335
338
340
341 using NotifyCreatedFunction = std::function<Error(LLJIT &)>;
342
343 std::unique_ptr<ExecutorProcessControl> EPC;
344 std::unique_ptr<ExecutionSession> ES;
345 std::optional<JITTargetMachineBuilder> JTMB;
346 std::optional<DataLayout> DL;
355 unsigned NumCompileThreads = 0;
356 std::optional<bool> SupportConcurrentCompilation;
357
358 /// Called prior to JIT class construcion to fix up defaults.
360};
361
362template <typename JITType, typename SetterImpl, typename State>
364public:
365 /// Set an ExecutorProcessControl for this instance.
366 /// This should not be called if ExecutionSession has already been set.
367 SetterImpl &
368 setExecutorProcessControl(std::unique_ptr<ExecutorProcessControl> EPC) {
369 assert(
370 !impl().ES &&
371 "setExecutorProcessControl should not be called if an ExecutionSession "
372 "has already been set");
373 impl().EPC = std::move(EPC);
374 return impl();
375 }
376
377 /// Set an ExecutionSession for this instance.
378 SetterImpl &setExecutionSession(std::unique_ptr<ExecutionSession> ES) {
379 assert(
380 !impl().EPC &&
381 "setExecutionSession should not be called if an ExecutorProcessControl "
382 "object has already been set");
383 impl().ES = std::move(ES);
384 return impl();
385 }
386
387 /// Set the JITTargetMachineBuilder for this instance.
388 ///
389 /// If this method is not called, JITTargetMachineBuilder::detectHost will be
390 /// used to construct a default target machine builder for the host platform.
392 impl().JTMB = std::move(JTMB);
393 return impl();
394 }
395
396 /// Return a reference to the JITTargetMachineBuilder.
397 ///
398 std::optional<JITTargetMachineBuilder> &getJITTargetMachineBuilder() {
399 return impl().JTMB;
400 }
401
402 /// Set a DataLayout for this instance. If no data layout is specified then
403 /// the target's default data layout will be used.
404 SetterImpl &setDataLayout(std::optional<DataLayout> DL) {
405 impl().DL = std::move(DL);
406 return impl();
407 }
408
409 /// The LinkProcessSymbolsDyDefault flag determines whether the "Process"
410 /// JITDylib will be added to the default link order at LLJIT construction
411 /// time. If true, the Process JITDylib will be added as the last item in the
412 /// default link order. If false (or if the Process JITDylib is disabled via
413 /// setProcessSymbolsJITDylibSetup) then the Process JITDylib will not appear
414 /// in the default link order.
415 SetterImpl &setLinkProcessSymbolsByDefault(bool LinkProcessSymbolsByDefault) {
416 impl().LinkProcessSymbolsByDefault = LinkProcessSymbolsByDefault;
417 return impl();
418 }
419
420 /// Set a memory manager creation function. If not provided then the
421 /// ExecutorProcessControl's createDefaultMemoryManager method will be used.
423 LLJITBuilderState::MemoryManagerCreator CreateMemoryManager) {
424 impl().CreateMemoryManager = std::move(CreateMemoryManager);
425 return impl();
426 }
427
428 /// Set a setup function for the process symbols dylib. If not provided,
429 /// but LinkProcessSymbolsJITDylibByDefault is true, then the process-symbols
430 /// JITDylib will be configured with a DynamicLibrarySearchGenerator with a
431 /// default symbol filter.
434 SetupProcessSymbolsJITDylib) {
435 impl().SetupProcessSymbolsJITDylib = std::move(SetupProcessSymbolsJITDylib);
436 return impl();
437 }
438
439 /// Set an ObjectLinkingLayer creation function.
440 ///
441 /// If this method is not called, a default creation function will be used
442 /// that will construct an RTDyldObjectLinkingLayer.
444 LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer) {
445 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);
446 return impl();
447 }
448
449 /// Set a CompileFunctionCreator.
450 ///
451 /// If this method is not called, a default creation function wil be used
452 /// that will construct a basic IR compile function that is compatible with
453 /// the selected number of threads (SimpleCompiler for '0' compile threads,
454 /// ConcurrentIRCompiler otherwise).
456 LLJITBuilderState::CompileFunctionCreator CreateCompileFunction) {
457 impl().CreateCompileFunction = std::move(CreateCompileFunction);
458 return impl();
459 }
460
461 /// Set a setup function to be run just before the PlatformSetupFunction is
462 /// run.
463 ///
464 /// This can be used to customize the LLJIT instance before the platform is
465 /// set up. E.g. By installing a debugger support plugin before the platform
466 /// is set up (when the ORC runtime is loaded) we enable debugging of the
467 /// runtime itself.
468 SetterImpl &
470 impl().PrePlatformSetup = std::move(PrePlatformSetup);
471 return impl();
472 }
473
474 /// Set up an PlatformSetupFunction.
475 ///
476 /// If this method is not called then setUpGenericLLVMIRPlatform
477 /// will be used to configure the JIT's platform support.
478 SetterImpl &
480 impl().SetUpPlatform = std::move(SetUpPlatform);
481 return impl();
482 }
483
484 /// Set up a callback after successful construction of the JIT.
485 ///
486 /// This is useful to attach generators to JITDylibs or inject initial symbol
487 /// definitions.
488 SetterImpl &
490 impl().NotifyCreated = std::move(Callback);
491 return impl();
492 }
493
494 /// Set the number of compile threads to use.
495 ///
496 /// If set to zero, compilation will be performed on the execution thread when
497 /// JITing in-process. If set to any other number N, a thread pool of N
498 /// threads will be created for compilation.
499 ///
500 /// If this method is not called, behavior will be as if it were called with
501 /// a zero argument.
502 ///
503 /// This setting should not be used if a custom ExecutionSession or
504 /// ExecutorProcessControl object is set: in those cases a custom
505 /// TaskDispatcher should be used instead.
506 SetterImpl &setNumCompileThreads(unsigned NumCompileThreads) {
507 impl().NumCompileThreads = NumCompileThreads;
508 return impl();
509 }
510
511 /// If set, this forces LLJIT concurrent compilation support to be either on
512 /// or off. This controls the selection of compile function (concurrent vs
513 /// single threaded) and whether or not sub-modules are cloned to new
514 /// contexts for lazy emission.
515 ///
516 /// If not explicitly set then concurrency support will be turned on if
517 /// NumCompileThreads is set to a non-zero value, or if a custom
518 /// ExecutionSession or ExecutorProcessControl instance is provided.
520 std::optional<bool> SupportConcurrentCompilation) {
521 impl().SupportConcurrentCompilation = SupportConcurrentCompilation;
522 return impl();
523 }
524
525 /// Create an instance of the JIT.
527 if (auto Err = impl().prepareForConstruction())
528 return std::move(Err);
529
530 Error Err = Error::success();
531 std::unique_ptr<JITType> J(new JITType(impl(), Err));
532 if (Err)
533 return std::move(Err);
534
535 if (impl().NotifyCreated)
536 if (Error Err = impl().NotifyCreated(*J))
537 return std::move(Err);
538
539 return std::move(J);
540 }
541
542protected:
543 SetterImpl &impl() { return static_cast<SetterImpl &>(*this); }
544};
545
546/// Constructs LLJIT instances.
548 : public LLJITBuilderState,
549 public LLJITBuilderSetters<LLJIT, LLJITBuilder, LLJITBuilderState> {};
550
552 friend class LLLazyJIT;
553
554public:
556 std::function<std::unique_ptr<IndirectStubsManager>()>;
557
560 std::unique_ptr<LazyCallThroughManager> LCTMgr;
562
564};
565
566template <typename JITType, typename SetterImpl, typename State>
568 : public LLJITBuilderSetters<JITType, SetterImpl, State> {
569public:
570 /// Set the address in the target address to call if a lazy compile fails.
571 ///
572 /// If this method is not called then the value will default to 0.
574 this->impl().LazyCompileFailureAddr = Addr;
575 return this->impl();
576 }
577
578 /// Set the lazy-callthrough manager.
579 ///
580 /// If this method is not called then a default, in-process lazy callthrough
581 /// manager for the host platform will be used.
582 SetterImpl &
583 setLazyCallthroughManager(std::unique_ptr<LazyCallThroughManager> LCTMgr) {
584 this->impl().LCTMgr = std::move(LCTMgr);
585 return this->impl();
586 }
587
588 /// Set the IndirectStubsManager builder function.
589 ///
590 /// If this method is not called then a default, in-process
591 /// IndirectStubsManager builder for the host platform will be used.
594 this->impl().ISMBuilder = std::move(ISMBuilder);
595 return this->impl();
596 }
597};
598
599/// Constructs LLLazyJIT instances.
601 : public LLLazyJITBuilderState,
602 public LLLazyJITBuilderSetters<LLLazyJIT, LLLazyJITBuilder,
603 LLLazyJITBuilderState> {};
604
605/// Configure the LLJIT instance to use orc runtime support. This overload
606/// assumes that the client has manually configured a Platform object.
608
609/// Configure the LLJIT instance to use the ORC runtime and the detected
610/// native target for the executor.
612public:
613 /// Set up using path to Orc runtime.
614 ExecutorNativePlatform(std::string OrcRuntimePath)
615 : OrcRuntime(std::move(OrcRuntimePath)) {}
616
617 /// Set up using the given memory buffer.
618 ExecutorNativePlatform(std::unique_ptr<MemoryBuffer> OrcRuntimeMB)
619 : OrcRuntime(std::move(OrcRuntimeMB)) {}
620
621 // TODO: add compiler-rt.
622
623 /// Add a path to the VC runtime.
624 ExecutorNativePlatform &addVCRuntime(std::string VCRuntimePath,
625 bool StaticVCRuntime) {
626 VCRuntime = {std::move(VCRuntimePath), StaticVCRuntime};
627 return *this;
628 }
629
631
632private:
633 std::variant<std::string, std::unique_ptr<MemoryBuffer>> OrcRuntime;
634 std::optional<std::pair<std::string, bool>> VCRuntime;
635};
636
637/// Configure the LLJIT instance to scrape modules for llvm.global_ctors and
638/// llvm.global_dtors variables and (if present) build initialization and
639/// deinitialization functions. Platform specific initialization configurations
640/// should be preferred where available.
642
643/// Configure the LLJIT instance to disable platform support explicitly. This is
644/// useful in two cases: for platforms that don't have such requirements and for
645/// platforms, that we have no explicit support yet and that don't work well
646/// with the generic IR platform.
648
649/// A Platform-support class that implements initialize / deinitialize by
650/// forwarding to ORC runtime dlopen / dlclose operations.
652public:
654 Error initialize(orc::JITDylib &JD) override;
655 Error deinitialize(orc::JITDylib &JD) override;
656
657private:
658 orc::LLJIT &J;
660 SmallPtrSet<JITDylib const *, 8> InitializedDylib;
661};
662
663} // End namespace orc
664} // End namespace llvm
665
666#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:215
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:56
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
An ExecutionSession represents a running JIT program.
Definition Core.h:1131
Represents an address in the executor process.
ExecutorNativePlatform & addVCRuntime(std::string VCRuntimePath, bool StaticVCRuntime)
Add a path to the VC runtime.
Definition LLJIT.h:624
ExecutorNativePlatform(std::unique_ptr< MemoryBuffer > OrcRuntimeMB)
Set up using the given memory buffer.
Definition LLJIT.h:618
ExecutorNativePlatform(std::string OrcRuntimePath)
Set up using path to Orc runtime.
Definition LLJIT.h:614
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:695
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:415
SetterImpl & setNotifyCreatedCallback(LLJITBuilderState::NotifyCreatedFunction Callback)
Set up a callback after successful construction of the JIT.
Definition LLJIT.h:489
SetterImpl & setMemoryManagerCreator(LLJITBuilderState::MemoryManagerCreator CreateMemoryManager)
Set a memory manager creation function.
Definition LLJIT.h:422
std::optional< JITTargetMachineBuilder > & getJITTargetMachineBuilder()
Return a reference to the JITTargetMachineBuilder.
Definition LLJIT.h:398
SetterImpl & setPrePlatformSetup(unique_function< Error(LLJIT &)> PrePlatformSetup)
Set a setup function to be run just before the PlatformSetupFunction is run.
Definition LLJIT.h:469
SetterImpl & setCompileFunctionCreator(LLJITBuilderState::CompileFunctionCreator CreateCompileFunction)
Set a CompileFunctionCreator.
Definition LLJIT.h:455
SetterImpl & setNumCompileThreads(unsigned NumCompileThreads)
Set the number of compile threads to use.
Definition LLJIT.h:506
SetterImpl & setDataLayout(std::optional< DataLayout > DL)
Set a DataLayout for this instance.
Definition LLJIT.h:404
SetterImpl & setJITTargetMachineBuilder(JITTargetMachineBuilder JTMB)
Set the JITTargetMachineBuilder for this instance.
Definition LLJIT.h:391
SetterImpl & setExecutorProcessControl(std::unique_ptr< ExecutorProcessControl > EPC)
Set an ExecutorProcessControl for this instance.
Definition LLJIT.h:368
SetterImpl & setObjectLinkingLayerCreator(LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer)
Set an ObjectLinkingLayer creation function.
Definition LLJIT.h:443
SetterImpl & setPlatformSetUp(LLJITBuilderState::PlatformSetupFunction SetUpPlatform)
Set up an PlatformSetupFunction.
Definition LLJIT.h:479
Expected< std::unique_ptr< JITType > > create()
Create an instance of the JIT.
Definition LLJIT.h:526
SetterImpl & setExecutionSession(std::unique_ptr< ExecutionSession > ES)
Set an ExecutionSession for this instance.
Definition LLJIT.h:378
SetterImpl & setSupportConcurrentCompilation(std::optional< bool > SupportConcurrentCompilation)
If set, this forces LLJIT concurrent compilation support to be either on or off.
Definition LLJIT.h:519
SetterImpl & setProcessSymbolsJITDylibSetup(LLJITBuilderState::ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib)
Set a setup function for the process symbols dylib.
Definition LLJIT.h:432
LLVM_ABI Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
Definition LLJIT.cpp:679
ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib
Definition LLJIT.h:348
ObjectLinkingLayerCreator CreateObjectLinkingLayer
Definition LLJIT.h:350
MemoryManagerCreator CreateMemoryManager
Definition LLJIT.h:349
std::function< Error(LLJIT &)> NotifyCreatedFunction
Definition LLJIT.h:341
std::unique_ptr< ExecutionSession > ES
Definition LLJIT.h:344
unique_function< Error(LLJIT &)> PrePlatformSetup
Definition LLJIT.h:352
std::function< Expected< std::unique_ptr< jitlink::JITLinkMemoryManager > >( ExecutionSession &)> MemoryManagerCreator
Definition LLJIT.h:324
CompileFunctionCreator CreateCompileFunction
Definition LLJIT.h:351
std::optional< bool > SupportConcurrentCompilation
Definition LLJIT.h:356
std::function< Expected< std::unique_ptr< ObjectLayer > >( ExecutionSession &, jitlink::JITLinkMemoryManager &)> ObjectLinkingLayerCreator
Definition LLJIT.h:328
std::unique_ptr< ExecutorProcessControl > EPC
Definition LLJIT.h:343
std::optional< DataLayout > DL
Definition LLJIT.h:346
std::optional< JITTargetMachineBuilder > JTMB
Definition LLJIT.h:345
unique_function< Expected< JITDylibSP >(LLJIT &J)> PlatformSetupFunction
Definition LLJIT.h:339
PlatformSetupFunction SetUpPlatform
Definition LLJIT.h:353
NotifyCreatedFunction NotifyCreated
Definition LLJIT.h:354
unique_function< Expected< JITDylibSP >(LLJIT &J)> ProcessSymbolsJITDylibSetupFunction
Definition LLJIT.h:336
std::function< Expected< std::unique_ptr< IRCompileLayer::IRCompiler > >( JITTargetMachineBuilder JTMB)> CompileFunctionCreator
Definition LLJIT.h:332
Constructs LLJIT instances.
Definition LLJIT.h:549
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:573
SetterImpl & setLazyCallthroughManager(std::unique_ptr< LazyCallThroughManager > LCTMgr)
Set the lazy-callthrough manager.
Definition LLJIT.h:583
SetterImpl & setIndirectStubsManagerBuilder(LLLazyJITBuilderState::IndirectStubsManagerBuilderFunction ISMBuilder)
Set the IndirectStubsManager builder function.
Definition LLJIT.h:592
ExecutorAddr LazyCompileFailureAddr
Definition LLJIT.h:559
std::function< std::unique_ptr< IndirectStubsManager >()> IndirectStubsManagerBuilderFunction
Definition LLJIT.h:555
std::unique_ptr< LazyCallThroughManager > LCTMgr
Definition LLJIT.h:560
LLVM_ABI Error prepareForConstruction()
Definition LLJIT.cpp:1298
IndirectStubsManagerBuilderFunction ISMBuilder
Definition LLJIT.h:561
Constructs LLLazyJIT instances.
Definition LLJIT.h:603
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:308
CompileOnDemandLayer & getCompileOnDemandLayer()
Returns a reference to the on-demand layer.
Definition LLJIT.h:302
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
LLVM_ABI ~LLLazyJIT()
Definition LLJIT.cpp:1318
ORCPlatformSupport(orc::LLJIT &J)
Definition LLJIT.h:653
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:168
IntrusiveRefCntPtr< JITDylib > JITDylibSP
Definition Core.h:58
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
Definition Core.h:57
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:209
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:878