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