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
247 std::unique_ptr<ExecutionSession> ES;
248 std::unique_ptr<PlatformSupport> PS;
249
251 JITDylib *Platform = nullptr;
252 JITDylib *Main = nullptr;
253
255
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.
275 IPLayer->setPartitionFunction(std::move(Partition));
276 }
277
278 /// Returns a reference to the on-demand layer.
280
281 /// Add a module to be lazily compiled to JITDylib JD.
283
284 /// Add a module to be lazily compiled to the main JITDylib.
286 return addLazyIRModule(*Main, std::move(M));
287 }
288
289private:
290
291 // Create a single-threaded LLLazyJIT instance.
293
294 std::unique_ptr<LazyCallThroughManager> LCTMgr;
295 std::unique_ptr<IRPartitionLayer> IPLayer;
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 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
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:1340
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
Expected< JITDylibSP > operator()(LLJIT &J)
Definition: LLJIT.cpp:1138
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: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
Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
Definition: LLJIT.cpp:685
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::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:48
virtual Error deinitialize(JITDylib &JD)=0
virtual Error initialize(JITDylib &JD)=0
static void setInitTransform(LLJIT &J, IRTransformLayer::TransformFunction T)
Definition: LLJIT.cpp:678
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:960
void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)
Set the PlatformSupport instance.
Definition: LLJIT.h:188
std::unique_ptr< ExecutionSession > ES
Definition: LLJIT.h:247
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Definition: LLJIT.cpp:938
Expected< JITDylib & > createJITDylib(std::string Name)
Create a new JITDylib with the given name and return a reference to it.
Definition: LLJIT.cpp:880
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
Definition: LLJIT.h:75
JITDylibSearchOrder DefaultLinks
Definition: LLJIT.h:254
const DataLayout & getDataLayout() const
Returns a reference to the DataLayout for this instance.
Definition: LLJIT.h:72
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: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:1220
virtual ~LLJIT()
Destruct this instance.
Definition: LLJIT.cpp:871
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:1090
JITDylib * Main
Definition: LLJIT.h:252
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:878
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:889
std::unique_ptr< IRTransformLayer > InitHelperTransformLayer
Definition: LLJIT.h:263
Error deinitialize(JITDylib &JD)
Run the deinitializers for the given JITDylib.
Definition: LLJIT.h:206
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: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:876
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:949
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
Definition: LLJIT.cpp:989
PlatformSupport * getPlatformSupport()
Get the PlatformSupport instance.
Definition: LLJIT.h:193
JITDylib * ProcessSymbols
Definition: LLJIT.h:250
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition: LLJIT.h:66
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:231
DataLayout DL
Definition: LLJIT.h:256
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:902
Error applyDataLayout(Module &M)
Definition: LLJIT.cpp:1099
std::unique_ptr< ObjectLayer > ObjLinkingLayer
Definition: LLJIT.h:259
std::unique_ptr< PlatformSupport > PS
Definition: LLJIT.h:248
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:257
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
Definition: LLJIT.cpp:924
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: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
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:268
void setPartitionFunction(IRPartitionLayer::PartitionFunction Partition)
Sets the partition function.
Definition: LLJIT.h:274
Error addLazyIRModule(ThreadSafeModule M)
Add a module to be lazily compiled to the main JITDylib.
Definition: LLJIT.h:285
CompileOnDemandLayer & getCompileOnDemandLayer()
Returns a reference to the on-demand layer.
Definition: LLJIT.h:279
Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
Definition: LLJIT.cpp:1252
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
Error deinitialize(orc::JITDylib &JD) override
Definition: LLJIT.cpp:653
Error initialize(orc::JITDylib &JD) override
Definition: LLJIT.cpp:609
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:1238
Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition: LLJIT.cpp:1220
Error setUpOrcPlatformManually(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
Definition: LLJIT.cpp:1113
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