34#define DEBUG_TYPE "orc"
60 std::vector<Type *> HelperArgTypes;
61 for (
auto *Arg : HelperPrefixArgs)
62 HelperArgTypes.push_back(Arg->getType());
63 for (
auto *
T : WrapperFnType->params())
64 HelperArgTypes.push_back(
T);
66 FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes,
false);
72 WrapperFn->setVisibility(WrapperVisibility);
77 std::vector<Value *> HelperArgs;
78 for (
auto *Arg : HelperPrefixArgs)
79 HelperArgs.push_back(Arg);
80 for (
auto &Arg : WrapperFn->args())
81 HelperArgs.push_back(&Arg);
82 auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
83 if (HelperFn->getReturnType()->isVoidTy())
86 IB.CreateRet(HelperResult);
98 using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t);
99 enum dlopen_mode : int32_t {
100 ORC_RT_RTLD_LAZY = 0x1,
101 ORC_RT_RTLD_NOW = 0x2,
102 ORC_RT_RTLD_LOCAL = 0x4,
103 ORC_RT_RTLD_GLOBAL = 0x8
110 if (
auto WrapperAddr =
111 ES.lookup(MainSearchOrder,
113 return ES.callSPSWrapper<SPSDLOpenSig>(WrapperAddr->getAddress(),
115 int32_t(ORC_RT_RTLD_LAZY));
117 return WrapperAddr.takeError();
122 using SPSDLCloseSig = int32_t(SPSExecutorAddr);
128 if (
auto WrapperAddr =
129 ES.lookup(MainSearchOrder,
133 WrapperAddr->getAddress(), result, DSOHandles[&JD]);
137 return make_error<StringError>(
"dlclose failed",
139 DSOHandles.erase(&JD);
141 return WrapperAddr.takeError();
150class GenericLLVMIRPlatformSupport;
154class GenericLLVMIRPlatform :
public Platform {
156 GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
167 GenericLLVMIRPlatformSupport &S;
173class GlobalCtorDtorScraper {
175 GlobalCtorDtorScraper(GenericLLVMIRPlatformSupport &PS,
178 : PS(PS), InitFunctionPrefix(InitFunctionPrefix),
179 DeInitFunctionPrefix(DeInitFunctionPrefix) {}
184 GenericLLVMIRPlatformSupport &PS;
197 : J(J), InitFunctionPrefix(J.
mangle(
"__orc_init_func.")),
198 DeInitFunctionPrefix(J.
mangle(
"__orc_deinit_func.")) {
201 std::make_unique<GenericLLVMIRPlatform>(*
this));
204 DeInitFunctionPrefix));
208 StdInterposes[J.
mangleAndIntern(
"__lljit.platform_support_instance")] = {
214 cantFail(setupJITDylib(PlatformJD));
231 auto Ctx = std::make_unique<LLVMContext>();
232 auto M = std::make_unique<Module>(
"__standard_lib", *Ctx);
241 DSOHandle->setInitializer(
244 auto *GenericIRPlatformSupportTy =
249 nullptr,
"__lljit.platform_support_instance");
253 *M,
"__lljit_run_atexits", FunctionType::get(VoidTy, {},
false),
255 {PlatformInstanceDecl, DSOHandle});
260 addHelperAndWrapper(*M,
"atexit",
261 FunctionType::get(IntTy, {AtExitCallbackPtrTy},
false),
263 {PlatformInstanceDecl, DSOHandle});
271 InitSymbols[&JD].add(InitSym, SymbolLookupFlags::WeaklyReferencedSymbol);
279 if ((*KV.first).startswith(InitFunctionPrefix)) {
280 InitSymbols[&JD].add(KV.first,
281 SymbolLookupFlags::WeaklyReferencedSymbol);
282 InitFunctions[&JD].add(KV.first);
283 }
else if ((*KV.first).startswith(DeInitFunctionPrefix)) {
284 DeInitFunctions[&JD].add(KV.first);
292 dbgs() <<
"GenericLLVMIRPlatformSupport getting initializers to run\n";
294 if (
auto Initializers = getInitializers(JD)) {
296 {
dbgs() <<
"GenericLLVMIRPlatformSupport running initializers\n"; });
297 for (
auto InitFnAddr : *Initializers) {
299 dbgs() <<
" Running init " <<
formatv(
"{0:x16}", InitFnAddr)
302 auto *InitFn = InitFnAddr.toPtr<void (*)()>();
306 return Initializers.takeError();
312 dbgs() <<
"GenericLLVMIRPlatformSupport getting deinitializers to run\n";
314 if (
auto Deinitializers = getDeinitializers(JD)) {
316 dbgs() <<
"GenericLLVMIRPlatformSupport running deinitializers\n";
318 for (
auto DeinitFnAddr : *Deinitializers) {
320 dbgs() <<
" Running deinit " <<
formatv(
"{0:x16}", DeinitFnAddr)
323 auto *DeinitFn = DeinitFnAddr.toPtr<void (*)()>();
327 return Deinitializers.takeError();
334 InitFunctions[&JD].add(InitName);
340 [&]() { DeInitFunctions[&JD].add(DeInitName); });
345 if (
auto Err = issueInitLookups(JD))
346 return std::move(Err);
349 std::vector<JITDylibSP> DFSLinkOrder;
353 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
355 return DFSLinkOrderOrErr.takeError();
357 for (
auto &NextJD : DFSLinkOrder) {
358 auto IFItr = InitFunctions.find(NextJD.get());
359 if (IFItr != InitFunctions.end()) {
360 LookupSymbols[NextJD.get()] = std::move(IFItr->second);
361 InitFunctions.erase(IFItr);
366 return std::move(Err);
369 dbgs() <<
"JITDylib init order is [ ";
373 dbgs() <<
"Looking up init functions:\n";
374 for (
auto &KV : LookupSymbols)
375 dbgs() <<
" \"" << KV.first->getName() <<
"\": " << KV.second <<
"\n";
382 return LookupResult.takeError();
384 std::vector<ExecutorAddr> Initializers;
385 while (!DFSLinkOrder.empty()) {
386 auto &NextJD = *DFSLinkOrder.back();
387 DFSLinkOrder.pop_back();
388 auto InitsItr = LookupResult->find(&NextJD);
389 if (InitsItr == LookupResult->end())
391 for (
auto &KV : InitsItr->second)
392 Initializers.push_back(KV.second.getAddress());
404 std::vector<JITDylibSP> DFSLinkOrder;
406 if (
auto Err = ES.runSessionLocked([&]() ->
Error {
407 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
408 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
410 return DFSLinkOrderOrErr.takeError();
412 for (auto &NextJD : DFSLinkOrder) {
413 auto &JDLookupSymbols = LookupSymbols[NextJD.get()];
414 auto DIFItr = DeInitFunctions.find(NextJD.get());
415 if (DIFItr != DeInitFunctions.end()) {
416 LookupSymbols[NextJD.get()] = std::move(DIFItr->second);
417 DeInitFunctions.erase(DIFItr);
419 JDLookupSymbols.add(LLJITRunAtExits,
420 SymbolLookupFlags::WeaklyReferencedSymbol);
424 return std::move(Err);
427 dbgs() <<
"JITDylib deinit order is [ ";
428 for (
auto &JD : DFSLinkOrder)
431 dbgs() <<
"Looking up deinit functions:\n";
432 for (
auto &KV : LookupSymbols)
433 dbgs() <<
" \"" << KV.first->getName() <<
"\": " << KV.second <<
"\n";
439 return LookupResult.takeError();
441 std::vector<ExecutorAddr> DeInitializers;
442 for (
auto &NextJD : DFSLinkOrder) {
443 auto DeInitsItr = LookupResult->find(NextJD.get());
444 assert(DeInitsItr != LookupResult->end() &&
445 "Every JD should have at least __lljit_run_atexits");
447 auto RunAtExitsItr = DeInitsItr->second.find(LLJITRunAtExits);
448 if (RunAtExitsItr != DeInitsItr->second.end())
449 DeInitializers.push_back(RunAtExitsItr->second.getAddress());
451 for (
auto &KV : DeInitsItr->second)
452 if (KV.first != LLJITRunAtExits)
453 DeInitializers.push_back(KV.second.getAddress());
456 return DeInitializers;
463 std::vector<JITDylibSP> DFSLinkOrder;
465 if (
auto Err = getExecutionSession().runSessionLocked([&]() ->
Error {
467 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
469 return DFSLinkOrderOrErr.takeError();
471 for (
auto &NextJD : DFSLinkOrder) {
472 auto ISItr = InitSymbols.find(NextJD.get());
473 if (ISItr != InitSymbols.end()) {
474 RequiredInitSymbols[NextJD.get()] = std::move(ISItr->second);
475 InitSymbols.erase(ISItr);
487 static void registerCxaAtExitHelper(
void *Self,
void (*
F)(
void *),
void *Ctx,
490 dbgs() <<
"Registering cxa atexit function " << (
void *)
F <<
" for JD "
493 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.registerAtExit(
497 static void registerAtExitHelper(
void *Self,
void *DSOHandle,
void (*
F)()) {
499 dbgs() <<
"Registering atexit function " << (
void *)
F <<
" for JD "
502 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.registerAtExit(
503 reinterpret_cast<void (*)(
void *)
>(
F),
nullptr, DSOHandle);
506 static void runAtExitsHelper(
void *Self,
void *DSOHandle) {
508 dbgs() <<
"Running atexit functions for JD "
509 << (*
static_cast<JITDylib **
>(DSOHandle))->getName() <<
"\n";
511 static_cast<GenericLLVMIRPlatformSupport *
>(Self)->AtExitMgr.runAtExits(
518 auto Ctx = std::make_unique<LLVMContext>();
519 auto M = std::make_unique<Module>(
"__standard_lib", *Ctx);
520 M->setDataLayout(J.getDataLayout());
522 auto *GenericIRPlatformSupportTy =
527 nullptr,
"__lljit.platform_support_instance");
532 auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
533 auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy},
false);
534 auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
538 FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
541 {PlatformInstanceDecl});
547 std::string InitFunctionPrefix;
548 std::string DeInitFunctionPrefix;
556 return S.setupJITDylib(JD);
565 return S.notifyAdding(RT, MU);
572 auto &Ctx =
M.getContext();
573 auto *GlobalCtors =
M.getNamedGlobal(
"llvm.global_ctors");
574 auto *GlobalDtors =
M.getNamedGlobal(
"llvm.global_dtors");
577 bool isCtor) ->
Error {
581 std::string InitOrDeInitFunctionName;
584 << InitFunctionPrefix <<
M.getModuleIdentifier();
587 << DeInitFunctionPrefix <<
M.getModuleIdentifier();
590 auto InternedInitOrDeInitName =
Mangle(InitOrDeInitFunctionName);
591 if (
auto Err =
R.defineMaterializing(
592 {{InternedInitOrDeInitName, JITSymbolFlags::Callable}}))
599 std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
602 for (
auto E : COrDtors)
603 InitsOrDeInits.push_back(std::make_pair(
E.Func,
E.Priority));
606 auto *InitOrDeInitFuncEntryBlock =
609 for (
auto &KV : InitsOrDeInits)
610 IB.CreateCall(KV.first);
614 PS.registerInitFunc(
R.getTargetJITDylib(), InternedInitOrDeInitName);
616 PS.registerDeInitFunc(
R.getTargetJITDylib(), InternedInitOrDeInitName);
622 if (
auto Err = RegisterCOrDtors(GlobalCtors,
true))
624 if (
auto Err = RegisterCOrDtors(GlobalDtors,
false))
631 return std::move(Err);
633 return std::move(TSM);
642 InactivePlatformSupport() =
default;
645 LLVM_DEBUG(
dbgs() <<
"InactivePlatformSupport: no initializers running for "
652 dbgs() <<
"InactivePlatformSupport: no deinitializers running for "
676 dbgs() <<
" No explicitly set JITTargetMachineBuilder. "
677 "Detecting host...\n";
680 JTMB = std::move(*JTMBOrErr);
682 return JTMBOrErr.takeError();
686 dbgs() <<
" JITTargetMachineBuilder is "
688 <<
" Pre-constructed ExecutionSession: " << (
ES ?
"Yes" :
"No")
694 dbgs() <<
"None (will be created by JITTargetMachineBuilder)\n";
696 dbgs() <<
" Custom object-linking-layer creator: "
697 << (CreateObjectLinkingLayer ?
"Yes" :
"No") <<
"\n"
698 <<
" Custom compile-function creator: "
699 << (CreateCompileFunction ?
"Yes" :
"No") <<
"\n"
700 <<
" Custom platform-setup function: "
701 << (SetUpPlatform ?
"Yes" :
"No") <<
"\n"
702 <<
" Number of compile threads: " << NumCompileThreads;
703 if (!NumCompileThreads)
704 dbgs() <<
" (code will be compiled on the execution thread)\n";
711 if (
auto DLOrErr = JTMB->getDefaultDataLayoutForTarget())
712 DL = std::move(*DLOrErr);
714 return DLOrErr.takeError();
720 dbgs() <<
"ExecutorProcessControl not specified, "
721 "Creating SelfExecutorProcessControl instance\n";
724 EPC = std::move(*EPCOrErr);
726 return EPCOrErr.takeError();
729 dbgs() <<
"Using explicitly specified ExecutorProcessControl instance "
730 << EPC.get() <<
"\n";
734 dbgs() <<
"Using explicitly specified ExecutionSession instance "
741 if (!CreateObjectLinkingLayer) {
742 auto &
TT = JTMB->getTargetTriple();
743 bool UseJITLink =
false;
767 CreateObjectLinkingLayer =
773 std::make_unique<EHFrameRegistrationPlugin>(
774 ES, std::move(*EHFrameRegistrar)));
776 return EHFrameRegistrar.takeError();
784 if (!SetupProcessSymbolsJITDylib &&
785 (LinkProcessSymbolsByDefault || EnableDebuggerSupport)) {
788 dbgs() <<
"Creating default Process JD setup function (neeeded for";
789 if (LinkProcessSymbolsByDefault)
790 dbgs() <<
" <link-process-syms-by-default>";
791 if (EnableDebuggerSupport)
792 dbgs() <<
" <debugger-support>";
802 return G.takeError();
814 if (
auto Err =
ES->endSession())
815 ES->reportError(std::move(Err));
823 auto JD =
ES->createJITDylib(std::move(
Name));
825 return JD.takeError();
834 return G.takeError();
836 if (
auto *ExistingJD =
ES->getJITDylibByName(Path))
839 auto &JD =
ES->createBareJITDylib(Path);
845 std::unique_ptr<MemoryBuffer> LibBuffer) {
847 std::move(LibBuffer));
849 return G.takeError();
859 return G.takeError();
867 assert(TSM &&
"Can not add null module");
881 std::unique_ptr<MemoryBuffer> Obj) {
882 assert(Obj &&
"Can not add null object");
893 if (
auto Sym =
ES->lookup(
896 return Sym->getAddress();
898 return Sym.takeError();
910 auto GetMemMgr = []() {
return std::make_unique<SectionMemoryManager>(); };
912 std::make_unique<RTDyldObjectLinkingLayer>(
ES, std::move(GetMemMgr));
914 if (S.
JTMB->getTargetTriple().isOSBinFormatCOFF()) {
915 Layer->setOverrideObjectFlagsWithResponsibilityFlags(
true);
916 Layer->setAutoClaimResponsibilityForObjectSymbols(
true);
919 if (S.
JTMB->getTargetTriple().isOSBinFormatELF() &&
922 Layer->setAutoClaimResponsibilityForObjectSymbols(
true);
927 return std::unique_ptr<ObjectLayer>(std::move(Layer));
941 return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
945 return TM.takeError();
947 return std::make_unique<TMOwningSimpleCompiler>(std::move(*
TM));
955 assert(!(S.
EPC && S.
ES) &&
"EPC and ES should not both be set");
958 ES = std::make_unique<ExecutionSession>(std::move(S.
EPC));
960 ES = std::move(S.
ES);
963 ES = std::make_unique<ExecutionSession>(std::move(*EPC));
965 Err = EPC.takeError();
972 Err = ObjLayer.takeError();
981 if (!CompileFunction) {
982 Err = CompileFunction.takeError();
996 ES->setDispatchTask([
this](std::unique_ptr<Task>
T) {
1002 std::unique_ptr<Task> T(UnownedT);
1012 Err = ProcSymsJD.takeError();
1018 if (
auto *OLL = dyn_cast<ObjectLinkingLayer>(
ObjLinkingLayer.get())) {
1023 Err = Registrar.takeError();
1026 OLL->addPlugin(std::make_unique<DebugObjectManagerPlugin>(
1027 *
ES, std::move(*Registrar),
true,
true));
1032 "EnableDebuggerSupport is set");
1036 Err = DS.takeError();
1039 OLL->addPlugin(std::move(*DS));
1044 dbgs() <<
"Cannot enable LLJIT debugger support: "
1046 <<
" not supported.\n";
1051 dbgs() <<
"Cannot enable LLJIT debugger support: "
1052 " debugger support is only available when using JITLink.\n";
1066 Err = PlatformJDOrErr.takeError();
1077 Err = MainOrErr.takeError();
1083 std::string MangledName;
1092 if (M.getDataLayout().isDefault())
1093 M.setDataLayout(
DL);
1095 if (M.getDataLayout() !=
DL)
1096 return make_error<StringError>(
1097 "Added modules have incompatible data layouts: " +
1098 M.getDataLayout().getStringRepresentation() +
" (module) vs " +
1106 LLVM_DEBUG({
dbgs() <<
"Setting up orc platform support for LLJIT\n"; });
1116 return make_error<StringError>(
"DLLName not ending with .dll",
1118 auto DLLNameStr = DLLName.
str();
1121 return DLLJD.takeError();
1132 if (!ProcessSymbolsJD)
1133 return make_error<StringError>(
1134 "Native platforms require a process symbols JITDylib",
1141 if (!ObjLinkingLayer)
1142 return make_error<StringError>(
1143 "SetUpTargetPlatform requires ObjectLinkingLayer",
1146 std::unique_ptr<MemoryBuffer> RuntimeArchiveBuffer;
1147 if (OrcRuntime.index() == 0) {
1150 return A.takeError();
1151 RuntimeArchiveBuffer = std::move(*
A);
1153 RuntimeArchiveBuffer = std::move(std::get<1>(OrcRuntime));
1161 switch (TT.getObjectFormat()) {
1163 const char *VCRuntimePath =
nullptr;
1164 bool StaticVCRuntime =
false;
1166 VCRuntimePath = VCRuntime->first.c_str();
1167 StaticVCRuntime = VCRuntime->second;
1170 ES, *ObjLinkingLayer, PlatformJD, std::move(RuntimeArchiveBuffer),
1174 return P.takeError();
1179 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1181 return G.takeError();
1187 return P.takeError();
1192 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1194 return G.takeError();
1198 ES.setPlatform(std::move(*
P));
1200 return P.takeError();
1204 return make_error<StringError>(
"Unsupported object format in triple " +
1214 {
dbgs() <<
"Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
1216 if (!ProcessSymbolsJD)
1217 return make_error<StringError>(
1218 "Native platforms require a process symbols JITDylib",
1225 std::make_unique<GenericLLVMIRPlatformSupport>(J, PlatformJD));
1232 {
dbgs() <<
"Explicitly deactivated platform support for LLJIT\n"; });
1240 TT =
JTMB->getTargetTriple();
1245 assert(TSM &&
"Can not add null module");
1248 [&](
Module &M) ->
Error { return applyDataLayout(M); }))
1251 return CODLayer->add(JD, std::move(TSM));
1264 LCTMgr = std::move(S.
LCTMgr);
1268 LCTMgr = std::move(*LCTMgrOrErr);
1270 Err = LCTMgrOrErr.takeError();
1284 Err = make_error<StringError>(
"Could not construct "
1285 "IndirectStubsManagerBuilder for target " +
1292 CODLayer = std::make_unique<CompileOnDemandLayer>(
1296 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< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#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.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
char getGlobalPrefix() const
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...
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
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.
ObjectFormatType getObjectFormat() const
Get the object format for this triple.
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
static StringRef getObjectFormatTypeName(ObjectFormatType ObjectFormat)
Get the name for the Object format.
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< DynamicLibrarySearchGenerator > > GetForCurrentProcess(char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate())
Creates a DynamicLibrarySearchGenerator that searches for symbols in the current process.
static Expected< std::unique_ptr< EPCDynamicLibrarySearchGenerator > > Load(ExecutionSession &ES, const char *LibraryPath, SymbolPredicate Allow=SymbolPredicate())
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
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.
static Expected< std::unique_ptr< GDBJITDebugInfoRegistrationPlugin > > Create(ExecutionSession &ES, JITDylib &ProcessJD, const Triple &TT)
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
bool EnableDebuggerSupport
ObjectLinkingLayerCreator CreateObjectLinkingLayer
unsigned NumCompileThreads
std::unique_ptr< ExecutionSession > ES
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)
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< ThreadPool > CompileThreads
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.
Expected< std::unique_ptr< EPCDebugObjectRegistrar > > createJITLoaderGDBRegistrar(ExecutionSession &ES, std::optional< ExecutorAddr > RegistrationFunctionDylib=std::nullopt)
Create a ExecutorProcessControl-based DebugObjectRegistrar that emits debug objects to the GDB JIT in...
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:...