30#define DEBUG_TYPE "orc"
56 std::vector<Type *> HelperArgTypes;
57 for (
auto *Arg : HelperPrefixArgs)
58 HelperArgTypes.push_back(Arg->getType());
59 for (
auto *
T : WrapperFnType->params())
60 HelperArgTypes.push_back(
T);
62 FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes,
false);
68 WrapperFn->setVisibility(WrapperVisibility);
73 std::vector<Value *> HelperArgs;
74 for (
auto *Arg : HelperPrefixArgs)
75 HelperArgs.push_back(Arg);
76 for (
auto &Arg : WrapperFn->args())
77 HelperArgs.push_back(&Arg);
78 auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
79 if (HelperFn->getReturnType()->isVoidTy())
82 IB.CreateRet(HelperResult);
87class GenericLLVMIRPlatformSupport;
91class GenericLLVMIRPlatform :
public Platform {
93 GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
104 GenericLLVMIRPlatformSupport &S;
110class GlobalCtorDtorScraper {
112 GlobalCtorDtorScraper(GenericLLVMIRPlatformSupport &PS,
115 : PS(PS), InitFunctionPrefix(InitFunctionPrefix),
116 DeInitFunctionPrefix(DeInitFunctionPrefix) {}
121 GenericLLVMIRPlatformSupport &PS;
134 : J(J), InitFunctionPrefix(J.
mangle(
"__orc_init_func.")),
135 DeInitFunctionPrefix(J.
mangle(
"__orc_deinit_func.")) {
138 std::make_unique<GenericLLVMIRPlatform>(*
this));
141 DeInitFunctionPrefix));
145 StdInterposes[J.
mangleAndIntern(
"__lljit.platform_support_instance")] = {
151 cantFail(setupJITDylib(PlatformJD));
168 auto Ctx = std::make_unique<LLVMContext>();
169 auto M = std::make_unique<Module>(
"__standard_lib", *Ctx);
175 ConstantInt::get(Int64Ty,
reinterpret_cast<uintptr_t
>(&JD)),
178 DSOHandle->setInitializer(
181 auto *GenericIRPlatformSupportTy =
186 nullptr,
"__lljit.platform_support_instance");
190 *M,
"__lljit_run_atexits", FunctionType::get(VoidTy, {},
false),
192 {PlatformInstanceDecl, DSOHandle});
197 addHelperAndWrapper(*M,
"atexit",
198 FunctionType::get(IntTy, {AtExitCallbackPtrTy},
false),
200 {PlatformInstanceDecl, DSOHandle});
208 InitSymbols[&JD].add(InitSym, SymbolLookupFlags::WeaklyReferencedSymbol);
216 if ((*KV.first).starts_with(InitFunctionPrefix)) {
217 InitSymbols[&JD].add(KV.first,
218 SymbolLookupFlags::WeaklyReferencedSymbol);
219 InitFunctions[&JD].add(KV.first);
220 }
else if ((*KV.first).starts_with(DeInitFunctionPrefix)) {
221 DeInitFunctions[&JD].add(KV.first);
229 dbgs() <<
"GenericLLVMIRPlatformSupport getting initializers to run\n";
231 if (
auto Initializers = getInitializers(JD)) {
233 {
dbgs() <<
"GenericLLVMIRPlatformSupport running initializers\n"; });
234 for (
auto InitFnAddr : *Initializers) {
236 dbgs() <<
" Running init " <<
formatv(
"{0:x16}", InitFnAddr)
239 auto *InitFn = InitFnAddr.toPtr<void (*)()>();
243 return Initializers.takeError();
249 dbgs() <<
"GenericLLVMIRPlatformSupport getting deinitializers to run\n";
251 if (
auto Deinitializers = getDeinitializers(JD)) {
253 dbgs() <<
"GenericLLVMIRPlatformSupport running deinitializers\n";
255 for (
auto DeinitFnAddr : *Deinitializers) {
257 dbgs() <<
" Running deinit " <<
formatv(
"{0:x16}", DeinitFnAddr)
260 auto *DeinitFn = DeinitFnAddr.toPtr<void (*)()>();
264 return Deinitializers.takeError();
271 InitFunctions[&JD].add(InitName);
277 [&]() { DeInitFunctions[&JD].add(DeInitName); });
282 if (
auto Err = issueInitLookups(JD))
283 return std::move(Err);
286 std::vector<JITDylibSP> DFSLinkOrder;
290 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
292 return DFSLinkOrderOrErr.takeError();
294 for (
auto &NextJD : DFSLinkOrder) {
295 auto IFItr = InitFunctions.find(NextJD.get());
296 if (IFItr != InitFunctions.end()) {
297 LookupSymbols[NextJD.get()] = std::move(IFItr->second);
298 InitFunctions.erase(IFItr);
303 return std::move(Err);
306 dbgs() <<
"JITDylib init order is [ ";
310 dbgs() <<
"Looking up init functions:\n";
311 for (
auto &KV : LookupSymbols)
312 dbgs() <<
" \"" << KV.first->getName() <<
"\": " << KV.second <<
"\n";
319 return LookupResult.takeError();
321 std::vector<ExecutorAddr> Initializers;
322 while (!DFSLinkOrder.empty()) {
323 auto &NextJD = *DFSLinkOrder.back();
324 DFSLinkOrder.pop_back();
325 auto InitsItr = LookupResult->find(&NextJD);
326 if (InitsItr == LookupResult->end())
328 for (
auto &KV : InitsItr->second)
329 Initializers.push_back(KV.second.getAddress());
341 std::vector<JITDylibSP> DFSLinkOrder;
343 if (
auto Err = ES.runSessionLocked([&]() ->
Error {
344 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
345 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
347 return DFSLinkOrderOrErr.takeError();
349 for (auto &NextJD : DFSLinkOrder) {
350 auto &JDLookupSymbols = LookupSymbols[NextJD.get()];
351 auto DIFItr = DeInitFunctions.find(NextJD.get());
352 if (DIFItr != DeInitFunctions.end()) {
353 LookupSymbols[NextJD.get()] = std::move(DIFItr->second);
354 DeInitFunctions.erase(DIFItr);
356 JDLookupSymbols.add(LLJITRunAtExits,
357 SymbolLookupFlags::WeaklyReferencedSymbol);
361 return std::move(Err);
364 dbgs() <<
"JITDylib deinit order is [ ";
365 for (
auto &JD : DFSLinkOrder)
368 dbgs() <<
"Looking up deinit functions:\n";
369 for (
auto &KV : LookupSymbols)
370 dbgs() <<
" \"" << KV.first->getName() <<
"\": " << KV.second <<
"\n";
376 return LookupResult.takeError();
378 std::vector<ExecutorAddr> DeInitializers;
379 for (
auto &NextJD : DFSLinkOrder) {
380 auto DeInitsItr = LookupResult->find(NextJD.get());
381 assert(DeInitsItr != LookupResult->end() &&
382 "Every JD should have at least __lljit_run_atexits");
384 auto RunAtExitsItr = DeInitsItr->second.find(LLJITRunAtExits);
385 if (RunAtExitsItr != DeInitsItr->second.end())
386 DeInitializers.push_back(RunAtExitsItr->second.getAddress());
388 for (
auto &KV : DeInitsItr->second)
389 if (KV.first != LLJITRunAtExits)
390 DeInitializers.push_back(KV.second.getAddress());
393 return DeInitializers;
400 std::vector<JITDylibSP> DFSLinkOrder;
402 if (
auto Err = getExecutionSession().runSessionLocked([&]() ->
Error {
404 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
406 return DFSLinkOrderOrErr.takeError();
408 for (
auto &NextJD : DFSLinkOrder) {
409 auto ISItr = InitSymbols.find(NextJD.get());
410 if (ISItr != InitSymbols.end()) {
411 RequiredInitSymbols[NextJD.get()] = std::move(ISItr->second);
412 InitSymbols.erase(ISItr);
424 static void registerCxaAtExitHelper(
void *Self,
void (*
F)(
void *),
void *Ctx,
427 dbgs() <<
"Registering cxa atexit function " << (
void *)
F <<
" for JD "
430 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.registerAtExit(
434 static void registerAtExitHelper(
void *Self,
void *DSOHandle,
void (*
F)()) {
436 dbgs() <<
"Registering atexit function " << (
void *)
F <<
" for JD "
439 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.registerAtExit(
440 reinterpret_cast<void (*)(
void *)
>(
F),
nullptr, DSOHandle);
443 static void runAtExitsHelper(
void *Self,
void *DSOHandle) {
445 dbgs() <<
"Running atexit functions for JD "
446 << (*
static_cast<JITDylib **
>(DSOHandle))->getName() <<
"\n";
448 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.runAtExits(
455 auto Ctx = std::make_unique<LLVMContext>();
456 auto M = std::make_unique<Module>(
"__standard_lib", *Ctx);
457 M->setDataLayout(J.getDataLayout());
459 auto *GenericIRPlatformSupportTy =
464 nullptr,
"__lljit.platform_support_instance");
469 auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
470 auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy},
false);
471 auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
475 FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
478 {PlatformInstanceDecl});
484 std::string InitFunctionPrefix;
485 std::string DeInitFunctionPrefix;
493 return S.setupJITDylib(JD);
502 return S.notifyAdding(RT, MU);
509 auto &Ctx =
M.getContext();
510 auto *GlobalCtors =
M.getNamedGlobal(
"llvm.global_ctors");
511 auto *GlobalDtors =
M.getNamedGlobal(
"llvm.global_dtors");
514 bool isCtor) ->
Error {
518 std::string InitOrDeInitFunctionName;
521 << InitFunctionPrefix <<
M.getModuleIdentifier();
524 << DeInitFunctionPrefix <<
M.getModuleIdentifier();
527 auto InternedInitOrDeInitName =
Mangle(InitOrDeInitFunctionName);
528 if (
auto Err =
R.defineMaterializing(
529 {{InternedInitOrDeInitName, JITSymbolFlags::Callable}}))
536 std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
539 for (
auto E : COrDtors)
540 InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
543 auto *InitOrDeInitFuncEntryBlock =
546 for (
auto &KV : InitsOrDeInits)
547 IB.CreateCall(KV.first);
551 PS.registerInitFunc(
R.getTargetJITDylib(), InternedInitOrDeInitName);
553 PS.registerDeInitFunc(
R.getTargetJITDylib(), InternedInitOrDeInitName);
559 if (
auto Err = RegisterCOrDtors(GlobalCtors,
true))
561 if (
auto Err = RegisterCOrDtors(GlobalDtors,
false))
568 return std::move(Err);
570 return std::move(TSM);
579 InactivePlatformSupport() =
default;
582 LLVM_DEBUG(
dbgs() <<
"InactivePlatformSupport: no initializers running for "
589 dbgs() <<
"InactivePlatformSupport: no deinitializers running for "
603 using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t);
604 enum dlopen_mode : int32_t {
605 ORC_RT_RTLD_LAZY = 0x1,
606 ORC_RT_RTLD_NOW = 0x2,
607 ORC_RT_RTLD_LOCAL = 0x4,
608 ORC_RT_RTLD_GLOBAL = 0x8
615 if (
auto WrapperAddr = ES.lookup(
617 return ES.callSPSWrapper<SPSDLOpenSig>(WrapperAddr->getAddress(),
619 int32_t(ORC_RT_RTLD_LAZY));
621 return WrapperAddr.takeError();
626 using SPSDLCloseSig = int32_t(SPSExecutorAddr);
632 if (
auto WrapperAddr = ES.lookup(
636 WrapperAddr->getAddress(), result, DSOHandles[&JD]);
640 return make_error<StringError>(
"dlclose failed",
642 DSOHandles.erase(&JD);
644 return WrapperAddr.takeError();
661 dbgs() <<
" No explicitly set JITTargetMachineBuilder. "
662 "Detecting host...\n";
665 JTMB = std::move(*JTMBOrErr);
667 return JTMBOrErr.takeError();
671 dbgs() <<
" JITTargetMachineBuilder is "
673 <<
" Pre-constructed ExecutionSession: " << (
ES ?
"Yes" :
"No")
679 dbgs() <<
"None (will be created by JITTargetMachineBuilder)\n";
681 dbgs() <<
" Custom object-linking-layer creator: "
682 << (CreateObjectLinkingLayer ?
"Yes" :
"No") <<
"\n"
683 <<
" Custom compile-function creator: "
684 << (CreateCompileFunction ?
"Yes" :
"No") <<
"\n"
685 <<
" Custom platform-setup function: "
686 << (SetUpPlatform ?
"Yes" :
"No") <<
"\n"
687 <<
" Number of compile threads: " << NumCompileThreads;
688 if (!NumCompileThreads)
689 dbgs() <<
" (code will be compiled on the execution thread)\n";
696 if (
auto DLOrErr = JTMB->getDefaultDataLayoutForTarget())
697 DL = std::move(*DLOrErr);
699 return DLOrErr.takeError();
705 dbgs() <<
"ExecutorProcessControl not specified, "
706 "Creating SelfExecutorProcessControl instance\n";
709 EPC = std::move(*EPCOrErr);
711 return EPCOrErr.takeError();
714 dbgs() <<
"Using explicitly specified ExecutorProcessControl instance "
715 << EPC.get() <<
"\n";
719 dbgs() <<
"Using explicitly specified ExecutionSession instance "
726 if (!CreateObjectLinkingLayer) {
727 auto &
TT = JTMB->getTargetTriple();
728 bool UseJITLink =
false;
758 CreateObjectLinkingLayer =
764 std::make_unique<EHFrameRegistrationPlugin>(
765 ES, std::move(*EHFrameRegistrar)));
767 return EHFrameRegistrar.takeError();
775 if (!SetupProcessSymbolsJITDylib && LinkProcessSymbolsByDefault) {
776 LLVM_DEBUG(
dbgs() <<
"Creating default Process JD setup function\n");
781 J.getExecutionSession());
783 return G.takeError();
795 if (
auto Err =
ES->endSession())
796 ES->reportError(std::move(Err));
804 auto JD =
ES->createJITDylib(std::move(
Name));
806 return JD.takeError();
815 return G.takeError();
817 if (
auto *ExistingJD =
ES->getJITDylibByName(Path))
820 auto &JD =
ES->createBareJITDylib(Path);
826 std::unique_ptr<MemoryBuffer> LibBuffer) {
828 std::move(LibBuffer));
830 return G.takeError();
840 return G.takeError();
848 assert(TSM &&
"Can not add null module");
862 std::unique_ptr<MemoryBuffer> Obj) {
863 assert(Obj &&
"Can not add null object");
874 if (
auto Sym =
ES->lookup(
877 return Sym->getAddress();
879 return Sym.takeError();
891 auto GetMemMgr = []() {
return std::make_unique<SectionMemoryManager>(); };
893 std::make_unique<RTDyldObjectLinkingLayer>(
ES, std::move(GetMemMgr));
895 if (S.
JTMB->getTargetTriple().isOSBinFormatCOFF()) {
896 Layer->setOverrideObjectFlagsWithResponsibilityFlags(
true);
897 Layer->setAutoClaimResponsibilityForObjectSymbols(
true);
900 if (S.
JTMB->getTargetTriple().isOSBinFormatELF() &&
903 Layer->setAutoClaimResponsibilityForObjectSymbols(
true);
908 return std::unique_ptr<ObjectLayer>(std::move(Layer));
922 return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
926 return TM.takeError();
928 return std::make_unique<TMOwningSimpleCompiler>(std::move(*
TM));
936 assert(!(S.
EPC && S.
ES) &&
"EPC and ES should not both be set");
939 ES = std::make_unique<ExecutionSession>(std::move(S.
EPC));
941 ES = std::move(S.
ES);
944 ES = std::make_unique<ExecutionSession>(std::move(*EPC));
946 Err = EPC.takeError();
953 Err = ObjLayer.takeError();
962 if (!CompileFunction) {
963 Err = CompileFunction.takeError();
977 ES->setDispatchTask([
this](std::unique_ptr<Task>
T) {
983 std::unique_ptr<Task> T(UnownedT);
993 Err = ProcSymsJD.takeError();
1000 Err = std::move(Err2);
1014 Err = PlatformJDOrErr.takeError();
1025 Err = MainOrErr.takeError();
1031 std::string MangledName;
1040 if (M.getDataLayout().isDefault())
1041 M.setDataLayout(
DL);
1043 if (M.getDataLayout() !=
DL)
1044 return make_error<StringError>(
1045 "Added modules have incompatible data layouts: " +
1046 M.getDataLayout().getStringRepresentation() +
" (module) vs " +
1054 LLVM_DEBUG({
dbgs() <<
"Setting up orc platform support for LLJIT\n"; });
1064 return make_error<StringError>(
"DLLName not ending with .dll",
1066 auto DLLNameStr = DLLName.
str();
1069 return DLLJD.takeError();
1080 if (!ProcessSymbolsJD)
1081 return make_error<StringError>(
1082 "Native platforms require a process symbols JITDylib",
1089 if (!ObjLinkingLayer)
1090 return make_error<StringError>(
1091 "ExecutorNativePlatform requires ObjectLinkingLayer",
1094 std::unique_ptr<MemoryBuffer> RuntimeArchiveBuffer;
1095 if (OrcRuntime.index() == 0) {
1098 return A.takeError();
1099 RuntimeArchiveBuffer = std::move(*
A);
1101 RuntimeArchiveBuffer = std::move(std::get<1>(OrcRuntime));
1109 switch (TT.getObjectFormat()) {
1111 const char *VCRuntimePath =
nullptr;
1112 bool StaticVCRuntime =
false;
1114 VCRuntimePath = VCRuntime->first.c_str();
1115 StaticVCRuntime = VCRuntime->second;
1118 ES, *ObjLinkingLayer, PlatformJD, std::move(RuntimeArchiveBuffer),
1122 return P.takeError();
1127 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1129 return G.takeError();
1135 return P.takeError();
1140 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1142 return G.takeError();
1146 ES.setPlatform(std::move(*
P));
1148 return P.takeError();
1152 return make_error<StringError>(
"Unsupported object format in triple " +
1162 {
dbgs() <<
"Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
1164 if (!ProcessSymbolsJD)
1165 return make_error<StringError>(
1166 "Native platforms require a process symbols JITDylib",
1173 std::make_unique<GenericLLVMIRPlatformSupport>(J, PlatformJD));
1180 {
dbgs() <<
"Explicitly deactivated platform support for LLJIT\n"; });
1188 TT =
JTMB->getTargetTriple();
1193 assert(TSM &&
"Can not add null module");
1196 [&](
Module &M) ->
Error { return applyDataLayout(M); }))
1199 return CODLayer->add(JD, std::move(TSM));
1212 LCTMgr = std::move(S.
LCTMgr);
1216 LCTMgr = std::move(*LCTMgrOrErr);
1218 Err = LCTMgrOrErr.takeError();
1232 Err = make_error<StringError>(
"Could not construct "
1233 "IndirectStubsManagerBuilder for target " +
1240 CODLayer = std::make_unique<CompileOnDemandLayer>(
1244 CODLayer->setCloneToNewContextOnEmit(
true);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ATTRIBUTE_USED
Module.h This file contains the declarations for the Module class.
const char LLVMTargetMachineRef TM
static StringRef getName(Value *V)
llvm::orc::shared::CWrapperFunctionResult llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size)
llvm::orc::shared::CWrapperFunctionResult llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ExternalLinkage
Externally visible function.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Flags for symbols in the JIT.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
A Module instance is used to store all the information related to an LLVM module.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
bool ends_with_insensitive(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Triple - Helper class for working with autoconf configuration names.
bool isPPC64ELFv2ABI() const
Tests whether the target 64-bit PowerPC big endian ABI is ELFv2.
ArchType getArch() const
Get the parsed architecture type of this triple.
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
const std::string & str() const
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
const std::string & getName() const
Get the name for this JITLinkDylib.
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > Load(ExecutionSession &ES, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > GetForTargetProcess(ExecutionSession &ES, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Creates a EPCDynamicLibrarySearchGenerator that searches for symbols in the target process.
static Expected< std::unique_ptr< EPCEHFrameRegistrar > > Create(ExecutionSession &ES)
Create from a ExecutorProcessControl instance alone.
An ExecutionSession represents a running JIT program.
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
An interface for Itanium __cxa_atexit interposer implementations.
Represents a JIT'd dynamic library.
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
void addToLinkOrder(const JITDylibSearchOrder &NewLinks)
Append the given JITDylibSearchOrder to the link order for this JITDylib (discarding any elements alr...
static Expected< std::vector< JITDylibSP > > getDFSLinkOrder(ArrayRef< JITDylibSP > JDs)
Returns the given JITDylibs and all of their transitive dependencies in DFS order (based on linkage r...
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
A utility class for building TargetMachines for JITs.
static Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib
ObjectLinkingLayerCreator CreateObjectLinkingLayer
unsigned NumCompileThreads
std::unique_ptr< ExecutionSession > ES
unique_function< Error(LLJIT &)> PrePlatformSetup
CompileFunctionCreator CreateCompileFunction
bool LinkProcessSymbolsByDefault
std::unique_ptr< ExecutorProcessControl > EPC
std::optional< JITTargetMachineBuilder > JTMB
PlatformSetupFunction SetUpPlatform
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
static Expected< std::unique_ptr< ObjectLayer > > createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES)
void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)
Set the PlatformSupport instance.
std::unique_ptr< ExecutionSession > ES
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Expected< JITDylib & > createJITDylib(std::string Name)
Create a new JITDylib with the given name and return a reference to it.
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
JITDylibSearchOrder DefaultLinks
const DataLayout & getDataLayout() const
Returns a reference to the DataLayout for this instance.
ObjectLayer & getObjLinkingLayer()
Returns a reference to the ObjLinkingLayer.
std::unique_ptr< ObjectTransformLayer > ObjTransformLayer
friend Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
virtual ~LLJIT()
Destruct this instance.
std::string mangle(StringRef UnmangledName) const
Returns a linker-mangled version of UnmangledName.
JITDylibSP getPlatformJITDylib()
Returns the Platform JITDylib, which will contain the ORC runtime (if given) and any platform symbols...
Expected< JITDylib & > loadPlatformDynamicLibrary(const char *Path)
Load a (real) dynamic library and make its symbols available through a new JITDylib with the same nam...
std::unique_ptr< IRTransformLayer > InitHelperTransformLayer
std::unique_ptr< IRCompileLayer > CompileLayer
const Triple & getTargetTriple() const
Returns a reference to the triple for this instance.
JITDylibSP getProcessSymbolsJITDylib()
Returns the ProcessSymbols JITDylib, which by default reflects non-JIT'd symbols in the host process.
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...
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
std::unique_ptr< DefaultThreadPool > CompileThreads
JITDylib * ProcessSymbols
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
std::unique_ptr< IRTransformLayer > TransformLayer
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Error linkStaticLibraryInto(JITDylib &JD, std::unique_ptr< MemoryBuffer > LibBuffer)
Link a static library into the given JITDylib.
Error applyDataLayout(Module &M)
std::unique_ptr< ObjectLayer > ObjLinkingLayer
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
ExecutorAddr LazyCompileFailureAddr
std::unique_ptr< LazyCallThroughManager > LCTMgr
Error prepareForConstruction()
IndirectStubsManagerBuilderFunction ISMBuilder
Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
LoadAndLinkDynLibrary(LLJIT &J)
Error operator()(JITDylib &JD, StringRef DLLName)
Mangles symbol names then uniques them in the context of an ExecutionSession.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
An ObjectLayer implementation built on JITLink.
API to remove / transfer ownership of JIT resources.
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
static Expected< std::unique_ptr< SelfExecutorProcessControl > > Create(std::shared_ptr< SymbolStringPool > SSP=nullptr, std::unique_ptr< TaskDispatcher > D=nullptr, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr=nullptr)
Create a SelfExecutorProcessControl with the given symbol string pool and memory manager.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibraryDefinitionGenerator from the given path.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, std::unique_ptr< object::Archive > Archive, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibrarySearchGenerator from the given memory buffer and Archive object.
Pointer to a pooled string representing a symbol name.
An LLVM Module together with a shared ThreadSafeContext.
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module.
SPS tag type for sequences.
A raw_ostream that writes to an std::string.
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
@ MatchExportedSymbolsOnly
Expected< JITDylibSP > setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
LLVM_ATTRIBUTE_USED void linkComponents()
std::function< std::unique_ptr< IndirectStubsManager >()> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indirect stubs manager builder.
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, ExecutorAddr ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session.
Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Error setUpOrcPlatformManually(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
This is an optimization pass for GlobalISel generic memory operations.
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Expected< T > errorOrToExpected(ErrorOr< T > &&EO)
Convert an ErrorOr<T> to an Expected<T>.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
Function object to check whether the second component of a container supported by std::get (like std:...