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