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