12#include "llvm/Config/llvm-config.h"
31#define DEBUG_TYPE "orc"
57 std::vector<Type *> HelperArgTypes;
58 for (
auto *Arg : HelperPrefixArgs)
59 HelperArgTypes.push_back(Arg->getType());
60 for (
auto *
T : WrapperFnType->params())
61 HelperArgTypes.push_back(
T);
63 FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes,
false);
69 WrapperFn->setVisibility(WrapperVisibility);
74 std::vector<Value *> HelperArgs;
75 for (
auto *Arg : HelperPrefixArgs)
76 HelperArgs.push_back(Arg);
77 for (
auto &Arg : WrapperFn->args())
78 HelperArgs.push_back(&Arg);
79 auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
80 if (HelperFn->getReturnType()->isVoidTy())
83 IB.CreateRet(HelperResult);
88class GenericLLVMIRPlatformSupport;
92class GenericLLVMIRPlatform :
public Platform {
94 GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
105 GenericLLVMIRPlatformSupport &S;
111class GlobalCtorDtorScraper {
113 GlobalCtorDtorScraper(GenericLLVMIRPlatformSupport &PS,
116 : PS(PS), InitFunctionPrefix(InitFunctionPrefix),
117 DeInitFunctionPrefix(DeInitFunctionPrefix) {}
122 GenericLLVMIRPlatformSupport &PS;
135 : J(J), InitFunctionPrefix(J.
mangle(
"__orc_init_func.")),
136 DeInitFunctionPrefix(J.
mangle(
"__orc_deinit_func.")) {
139 std::make_unique<GenericLLVMIRPlatform>(*
this));
142 DeInitFunctionPrefix));
146 StdInterposes[J.
mangleAndIntern(
"__lljit.platform_support_instance")] = {
152 cantFail(setupJITDylib(PlatformJD));
169 auto Ctx = std::make_unique<LLVMContext>();
170 auto M = std::make_unique<Module>(
"__standard_lib", *Ctx);
176 ConstantInt::get(Int64Ty,
reinterpret_cast<uintptr_t
>(&JD)),
179 DSOHandle->setInitializer(
182 auto *GenericIRPlatformSupportTy =
187 nullptr,
"__lljit.platform_support_instance");
191 *M,
"__lljit_run_atexits", FunctionType::get(VoidTy, {},
false),
193 {PlatformInstanceDecl, DSOHandle});
197 auto *AtExit = addHelperAndWrapper(
198 *M,
"atexit", FunctionType::get(IntTy, {AtExitCallbackPtrTy},
false),
200 {PlatformInstanceDecl, DSOHandle});
204 AtExit->addRetAttr(AtExitExtAttr);
212 InitSymbols[&JD].add(InitSym, SymbolLookupFlags::WeaklyReferencedSymbol);
220 if ((*KV.first).starts_with(InitFunctionPrefix)) {
221 InitSymbols[&JD].add(KV.first,
222 SymbolLookupFlags::WeaklyReferencedSymbol);
223 InitFunctions[&JD].add(KV.first);
224 }
else if ((*KV.first).starts_with(DeInitFunctionPrefix)) {
225 DeInitFunctions[&JD].add(KV.first);
233 dbgs() <<
"GenericLLVMIRPlatformSupport getting initializers to run\n";
235 if (
auto Initializers = getInitializers(JD)) {
237 {
dbgs() <<
"GenericLLVMIRPlatformSupport running initializers\n"; });
238 for (
auto InitFnAddr : *Initializers) {
240 dbgs() <<
" Running init " <<
formatv(
"{0:x16}", InitFnAddr)
243 auto *InitFn = InitFnAddr.toPtr<void (*)()>();
247 return Initializers.takeError();
253 dbgs() <<
"GenericLLVMIRPlatformSupport getting deinitializers to run\n";
255 if (
auto Deinitializers = getDeinitializers(JD)) {
257 dbgs() <<
"GenericLLVMIRPlatformSupport running deinitializers\n";
259 for (
auto DeinitFnAddr : *Deinitializers) {
261 dbgs() <<
" Running deinit " <<
formatv(
"{0:x16}", DeinitFnAddr)
264 auto *DeinitFn = DeinitFnAddr.toPtr<void (*)()>();
268 return Deinitializers.takeError();
275 InitFunctions[&JD].add(InitName);
281 [&]() { DeInitFunctions[&JD].add(DeInitName); });
286 if (
auto Err = issueInitLookups(JD))
287 return std::move(Err);
290 std::vector<JITDylibSP> DFSLinkOrder;
294 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
296 return DFSLinkOrderOrErr.takeError();
298 for (
auto &NextJD : DFSLinkOrder) {
299 auto IFItr = InitFunctions.find(NextJD.get());
300 if (IFItr != InitFunctions.end()) {
301 LookupSymbols[NextJD.get()] = std::move(IFItr->second);
302 InitFunctions.erase(IFItr);
307 return std::move(Err);
310 dbgs() <<
"JITDylib init order is [ ";
314 dbgs() <<
"Looking up init functions:\n";
315 for (
auto &KV : LookupSymbols)
316 dbgs() <<
" \"" << KV.first->getName() <<
"\": " << KV.second <<
"\n";
323 return LookupResult.takeError();
325 std::vector<ExecutorAddr> Initializers;
326 while (!DFSLinkOrder.empty()) {
327 auto &NextJD = *DFSLinkOrder.back();
328 DFSLinkOrder.pop_back();
329 auto InitsItr = LookupResult->find(&NextJD);
330 if (InitsItr == LookupResult->end())
332 for (
auto &KV : InitsItr->second)
333 Initializers.push_back(KV.second.getAddress());
345 std::vector<JITDylibSP> DFSLinkOrder;
347 if (
auto Err = ES.runSessionLocked([&]() ->
Error {
348 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
349 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
351 return DFSLinkOrderOrErr.takeError();
353 for (auto &NextJD : DFSLinkOrder) {
354 auto &JDLookupSymbols = LookupSymbols[NextJD.get()];
355 auto DIFItr = DeInitFunctions.find(NextJD.get());
356 if (DIFItr != DeInitFunctions.end()) {
357 LookupSymbols[NextJD.get()] = std::move(DIFItr->second);
358 DeInitFunctions.erase(DIFItr);
360 JDLookupSymbols.add(LLJITRunAtExits,
361 SymbolLookupFlags::WeaklyReferencedSymbol);
365 return std::move(Err);
368 dbgs() <<
"JITDylib deinit order is [ ";
369 for (
auto &JD : DFSLinkOrder)
372 dbgs() <<
"Looking up deinit functions:\n";
373 for (
auto &KV : LookupSymbols)
374 dbgs() <<
" \"" << KV.first->getName() <<
"\": " << KV.second <<
"\n";
380 return LookupResult.takeError();
382 std::vector<ExecutorAddr> DeInitializers;
383 for (
auto &NextJD : DFSLinkOrder) {
384 auto DeInitsItr = LookupResult->find(NextJD.get());
385 assert(DeInitsItr != LookupResult->end() &&
386 "Every JD should have at least __lljit_run_atexits");
388 auto RunAtExitsItr = DeInitsItr->second.find(LLJITRunAtExits);
389 if (RunAtExitsItr != DeInitsItr->second.end())
390 DeInitializers.push_back(RunAtExitsItr->second.getAddress());
392 for (
auto &KV : DeInitsItr->second)
393 if (KV.first != LLJITRunAtExits)
394 DeInitializers.push_back(KV.second.getAddress());
397 return DeInitializers;
404 std::vector<JITDylibSP> DFSLinkOrder;
406 if (
auto Err = getExecutionSession().runSessionLocked([&]() ->
Error {
408 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
410 return DFSLinkOrderOrErr.takeError();
412 for (
auto &NextJD : DFSLinkOrder) {
413 auto ISItr = InitSymbols.find(NextJD.get());
414 if (ISItr != InitSymbols.end()) {
415 RequiredInitSymbols[NextJD.get()] = std::move(ISItr->second);
416 InitSymbols.erase(ISItr);
428 static void registerCxaAtExitHelper(
void *Self,
void (*
F)(
void *),
void *Ctx,
431 dbgs() <<
"Registering cxa atexit function " << (
void *)
F <<
" for JD "
434 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.registerAtExit(
438 static void registerAtExitHelper(
void *Self,
void *DSOHandle,
void (*
F)()) {
440 dbgs() <<
"Registering atexit function " << (
void *)
F <<
" for JD "
443 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.registerAtExit(
444 reinterpret_cast<void (*)(
void *)
>(
F),
nullptr, DSOHandle);
447 static void runAtExitsHelper(
void *Self,
void *DSOHandle) {
449 dbgs() <<
"Running atexit functions for JD "
450 << (*
static_cast<JITDylib **
>(DSOHandle))->getName() <<
"\n";
452 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.runAtExits(
459 auto Ctx = std::make_unique<LLVMContext>();
460 auto M = std::make_unique<Module>(
"__standard_lib", *Ctx);
461 M->setDataLayout(J.getDataLayout());
463 auto *GenericIRPlatformSupportTy =
468 nullptr,
"__lljit.platform_support_instance");
471 auto *BytePtrTy = PointerType::getUnqual(*Ctx);
472 auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(*Ctx);
474 auto *CxaAtExit = addHelperAndWrapper(
476 FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
479 {PlatformInstanceDecl});
481 TargetLibraryInfo::getExtAttrForI32Return(J.getTargetTriple());
483 CxaAtExit->addRetAttr(CxaAtExitExtAttr);
489 std::string InitFunctionPrefix;
490 std::string DeInitFunctionPrefix;
498 return S.setupJITDylib(JD);
507 return S.notifyAdding(RT, MU);
514 auto &Ctx =
M.getContext();
515 auto *GlobalCtors =
M.getNamedGlobal(
"llvm.global_ctors");
516 auto *GlobalDtors =
M.getNamedGlobal(
"llvm.global_dtors");
519 bool isCtor) ->
Error {
523 std::string InitOrDeInitFunctionName;
526 << InitFunctionPrefix <<
M.getModuleIdentifier();
529 << DeInitFunctionPrefix <<
M.getModuleIdentifier();
532 auto InternedInitOrDeInitName =
Mangle(InitOrDeInitFunctionName);
533 if (
auto Err =
R.defineMaterializing(
534 {{InternedInitOrDeInitName, JITSymbolFlags::Callable}}))
541 std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
544 for (
auto E : COrDtors)
545 InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
548 auto *InitOrDeInitFuncEntryBlock =
551 for (
auto &KV : InitsOrDeInits)
552 IB.CreateCall(KV.first);
556 PS.registerInitFunc(
R.getTargetJITDylib(), InternedInitOrDeInitName);
558 PS.registerDeInitFunc(
R.getTargetJITDylib(), InternedInitOrDeInitName);
564 if (
auto Err = RegisterCOrDtors(GlobalCtors,
true))
566 if (
auto Err = RegisterCOrDtors(GlobalDtors,
false))
573 return std::move(Err);
575 return std::move(TSM);
584 InactivePlatformSupport() =
default;
587 LLVM_DEBUG(
dbgs() <<
"InactivePlatformSupport: no initializers running for "
594 dbgs() <<
"InactivePlatformSupport: no deinitializers running for "
608 using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t);
609 using SPSDLUpdateSig = int32_t(SPSExecutorAddr);
610 enum dlopen_mode : int32_t {
611 ORC_RT_RTLD_LAZY = 0x1,
612 ORC_RT_RTLD_NOW = 0x2,
613 ORC_RT_RTLD_LOCAL = 0x4,
614 ORC_RT_RTLD_GLOBAL = 0x8
620 StringRef WrapperToCall =
"__orc_rt_jit_dlopen_wrapper";
621 bool dlupdate =
false;
622 const Triple &TT = ES.getTargetTriple();
623 if (TT.isOSBinFormatMachO() || TT.isOSBinFormatELF()) {
624 if (InitializedDylib.contains(&JD)) {
625 WrapperToCall =
"__orc_rt_jit_dlupdate_wrapper";
628 InitializedDylib.insert(&JD);
631 if (
auto WrapperAddr =
635 auto E = ES.callSPSWrapper<SPSDLUpdateSig>(WrapperAddr->getAddress(),
636 result, DSOHandles[&JD]);
638 return make_error<StringError>(
"dlupdate failed",
642 return ES.callSPSWrapper<SPSDLOpenSig>(WrapperAddr->getAddress(),
644 int32_t(ORC_RT_RTLD_LAZY));
646 return WrapperAddr.takeError();
651 using SPSDLCloseSig = int32_t(SPSExecutorAddr);
657 if (
auto WrapperAddr = ES.lookup(
661 WrapperAddr->getAddress(), result, DSOHandles[&JD]);
665 return make_error<StringError>(
"dlclose failed",
667 DSOHandles.erase(&JD);
668 InitializedDylib.erase(&JD);
670 return WrapperAddr.takeError();
687 dbgs() <<
" No explicitly set JITTargetMachineBuilder. "
688 "Detecting host...\n";
691 JTMB = std::move(*JTMBOrErr);
693 return JTMBOrErr.takeError();
696 if ((
ES || EPC) && NumCompileThreads)
697 return make_error<StringError>(
698 "NumCompileThreads cannot be used with a custom ExecutionSession or "
699 "ExecutorProcessControl",
702#if !LLVM_ENABLE_THREADS
703 if (NumCompileThreads)
704 return make_error<StringError>(
705 "LLJIT num-compile-threads is " +
Twine(NumCompileThreads) +
706 " but LLVM was compiled with LLVM_ENABLE_THREADS=Off",
711 [[maybe_unused]]
bool ConcurrentCompilationSettingDefaulted =
712 !SupportConcurrentCompilation;
714 if (!SupportConcurrentCompilation) {
715#if LLVM_ENABLE_THREADS
716 SupportConcurrentCompilation = NumCompileThreads ||
ES || EPC;
718 SupportConcurrentCompilation =
false;
721#if !LLVM_ENABLE_THREADS
722 if (*SupportConcurrentCompilation)
723 return make_error<StringError>(
724 "LLJIT concurrent compilation support requested, but LLVM was built "
725 "with LLVM_ENABLE_THREADS=Off",
731 dbgs() <<
" JITTargetMachineBuilder is "
733 <<
" Pre-constructed ExecutionSession: " << (
ES ?
"Yes" :
"No")
739 dbgs() <<
"None (will be created by JITTargetMachineBuilder)\n";
741 dbgs() <<
" Custom object-linking-layer creator: "
742 << (CreateObjectLinkingLayer ?
"Yes" :
"No") <<
"\n"
743 <<
" Custom compile-function creator: "
744 << (CreateCompileFunction ?
"Yes" :
"No") <<
"\n"
745 <<
" Custom platform-setup function: "
746 << (SetUpPlatform ?
"Yes" :
"No") <<
"\n"
747 <<
" Support concurrent compilation: "
748 << (*SupportConcurrentCompilation ?
"Yes" :
"No");
749 if (ConcurrentCompilationSettingDefaulted)
750 dbgs() <<
" (defaulted based on ES / EPC / NumCompileThreads)\n";
753 dbgs() <<
" Number of compile threads: " << NumCompileThreads <<
"\n";
758 if (
auto DLOrErr = JTMB->getDefaultDataLayoutForTarget())
759 DL = std::move(*DLOrErr);
761 return DLOrErr.takeError();
767 dbgs() <<
"ExecutorProcessControl not specified, "
768 "Creating SelfExecutorProcessControl instance\n";
771 std::unique_ptr<TaskDispatcher>
D =
nullptr;
772#if LLVM_ENABLE_THREADS
773 if (*SupportConcurrentCompilation) {
774 std::optional<size_t> NumThreads = std ::nullopt;
775 if (NumCompileThreads)
776 NumThreads = NumCompileThreads;
777 D = std::make_unique<DynamicThreadPoolTaskDispatcher>(NumThreads);
779 D = std::make_unique<InPlaceTaskDispatcher>();
783 EPC = std::move(*EPCOrErr);
785 return EPCOrErr.takeError();
788 dbgs() <<
"Using explicitly specified ExecutorProcessControl instance "
789 << EPC.get() <<
"\n";
793 dbgs() <<
"Using explicitly specified ExecutionSession instance "
800 if (!CreateObjectLinkingLayer) {
801 auto &
TT = JTMB->getTargetTriple();
802 bool UseJITLink =
false;
830 if (!JTMB->getCodeModel())
833 CreateObjectLinkingLayer =
839 std::make_unique<EHFrameRegistrationPlugin>(
840 ES, std::move(*EHFrameRegistrar)));
842 return EHFrameRegistrar.takeError();
850 if (!SetupProcessSymbolsJITDylib && LinkProcessSymbolsByDefault) {
851 LLVM_DEBUG(
dbgs() <<
"Creating default Process JD setup function\n");
856 J.getExecutionSession());
858 return G.takeError();
868 if (
auto Err =
ES->endSession())
869 ES->reportError(std::move(Err));
877 auto JD =
ES->createJITDylib(std::move(
Name));
879 return JD.takeError();
888 return G.takeError();
890 if (
auto *ExistingJD =
ES->getJITDylibByName(Path))
893 auto &JD =
ES->createBareJITDylib(Path);
899 std::unique_ptr<MemoryBuffer> LibBuffer) {
901 std::move(LibBuffer));
903 return G.takeError();
913 return G.takeError();
921 assert(TSM &&
"Can not add null module");
935 std::unique_ptr<MemoryBuffer> Obj) {
936 assert(Obj &&
"Can not add null object");
947 if (
auto Sym =
ES->lookup(
950 return Sym->getAddress();
952 return Sym.takeError();
964 auto GetMemMgr = []() {
return std::make_unique<SectionMemoryManager>(); };
966 std::make_unique<RTDyldObjectLinkingLayer>(
ES, std::move(GetMemMgr));
968 if (S.
JTMB->getTargetTriple().isOSBinFormatCOFF()) {
969 Layer->setOverrideObjectFlagsWithResponsibilityFlags(
true);
970 Layer->setAutoClaimResponsibilityForObjectSymbols(
true);
973 if (S.
JTMB->getTargetTriple().isOSBinFormatELF() &&
976 Layer->setAutoClaimResponsibilityForObjectSymbols(
true);
981 return std::unique_ptr<ObjectLayer>(std::move(Layer));
994 return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
998 return TM.takeError();
1000 return std::make_unique<TMOwningSimpleCompiler>(std::move(*TM));
1008 assert(!(S.
EPC && S.
ES) &&
"EPC and ES should not both be set");
1011 ES = std::make_unique<ExecutionSession>(std::move(S.
EPC));
1013 ES = std::move(S.
ES);
1016 ES = std::make_unique<ExecutionSession>(std::move(*EPC));
1018 Err = EPC.takeError();
1025 Err = ObjLayer.takeError();
1034 if (!CompileFunction) {
1035 Err = CompileFunction.takeError();
1052 Err = ProcSymsJD.takeError();
1070 Err = PlatformJDOrErr.takeError();
1081 Err = MainOrErr.takeError();
1087 std::string MangledName;
1096 if (M.getDataLayout().isDefault())
1097 M.setDataLayout(
DL);
1099 if (M.getDataLayout() !=
DL)
1100 return make_error<StringError>(
1101 "Added modules have incompatible data layouts: " +
1102 M.getDataLayout().getStringRepresentation() +
" (module) vs " +
1110 LLVM_DEBUG({
dbgs() <<
"Setting up orc platform support for LLJIT\n"; });
1120 return make_error<StringError>(
"DLLName not ending with .dll",
1122 auto DLLNameStr = DLLName.
str();
1125 return DLLJD.takeError();
1136 if (!ProcessSymbolsJD)
1137 return make_error<StringError>(
1138 "Native platforms require a process symbols JITDylib",
1145 if (!ObjLinkingLayer)
1146 return make_error<StringError>(
1147 "ExecutorNativePlatform requires ObjectLinkingLayer",
1150 std::unique_ptr<MemoryBuffer> RuntimeArchiveBuffer;
1151 if (OrcRuntime.index() == 0) {
1154 return A.takeError();
1155 RuntimeArchiveBuffer = std::move(*
A);
1157 RuntimeArchiveBuffer = std::move(std::get<1>(OrcRuntime));
1165 switch (TT.getObjectFormat()) {
1167 const char *VCRuntimePath =
nullptr;
1168 bool StaticVCRuntime =
false;
1170 VCRuntimePath = VCRuntime->first.c_str();
1171 StaticVCRuntime = VCRuntime->second;
1174 *ObjLinkingLayer, PlatformJD, std::move(RuntimeArchiveBuffer),
1178 return P.takeError();
1183 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1185 return G.takeError();
1191 return P.takeError();
1196 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1198 return G.takeError();
1202 ES.setPlatform(std::move(*
P));
1204 return P.takeError();
1208 return make_error<StringError>(
"Unsupported object format in triple " +
1218 {
dbgs() <<
"Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
1220 if (!ProcessSymbolsJD)
1221 return make_error<StringError>(
1222 "Native platforms require a process symbols JITDylib",
1229 std::make_unique<GenericLLVMIRPlatformSupport>(J, PlatformJD));
1236 {
dbgs() <<
"Explicitly deactivated platform support for LLJIT\n"; });
1244 TT =
JTMB->getTargetTriple();
1249 assert(TSM &&
"Can not add null module");
1252 [&](
Module &M) ->
Error { return applyDataLayout(M); }))
1255 return CODLayer->add(JD, std::move(TSM));
1268 LCTMgr = std::move(S.
LCTMgr);
1272 LCTMgr = std::move(*LCTMgrOrErr);
1274 Err = LCTMgrOrErr.takeError();
1288 Err = make_error<StringError>(
"Could not construct "
1289 "IndirectStubsManagerBuilder for target " +
1299 CODLayer = std::make_unique<CompileOnDemandLayer>(*
ES, *IPLayer, *LCTMgr,
1300 std::move(ISMBuilder));
1303 CODLayer->setCloneToNewContextOnEmit(
true);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ATTRIBUTE_USED
Module.h This file contains the declarations for the Module class.
static StringRef getName(Value *V)
LLVM_ABI llvm::orc::shared::CWrapperFunctionResult llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size)
LLVM_ABI 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),...
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
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 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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Type * getVoidTy(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
std::unique_ptr< ExecutionSession > ES
unique_function< Error(LLJIT &)> PrePlatformSetup
CompileFunctionCreator CreateCompileFunction
std::optional< bool > SupportConcurrentCompilation
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)
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 > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, std::unique_ptr< object::Archive > Archive, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibrarySearchGenerator from the given memory buffer and Archive object.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibraryDefinitionGenerator from the given path.
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.
void stable_sort(R &&Range)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
auto reverse(ContainerTy &&C)
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:...