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