LLVM 17.0.0git
LLJIT.cpp
Go to the documentation of this file.
1//===--------- LLJIT.cpp - An ORC-based JIT for compiling LLVM IR ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
22#include "llvm/IR/IRBuilder.h"
23#include "llvm/IR/Mangler.h"
24#include "llvm/IR/Module.h"
26
27#include <map>
28
29#define DEBUG_TYPE "orc"
30
31using namespace llvm;
32using namespace llvm::orc;
33
34namespace {
35
36/// Adds helper function decls and wrapper functions that call the helper with
37/// some additional prefix arguments.
38///
39/// E.g. For wrapper "foo" with type i8(i8, i64), helper "bar", and prefix
40/// args i32 4 and i16 12345, this function will add:
41///
42/// declare i8 @bar(i32, i16, i8, i64)
43///
44/// define i8 @foo(i8, i64) {
45/// entry:
46/// %2 = call i8 @bar(i32 4, i16 12345, i8 %0, i64 %1)
47/// ret i8 %2
48/// }
49///
50Function *addHelperAndWrapper(Module &M, StringRef WrapperName,
51 FunctionType *WrapperFnType,
52 GlobalValue::VisibilityTypes WrapperVisibility,
53 StringRef HelperName,
54 ArrayRef<Value *> HelperPrefixArgs) {
55 std::vector<Type *> HelperArgTypes;
56 for (auto *Arg : HelperPrefixArgs)
57 HelperArgTypes.push_back(Arg->getType());
58 for (auto *T : WrapperFnType->params())
59 HelperArgTypes.push_back(T);
60 auto *HelperFnType =
61 FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes, false);
62 auto *HelperFn = Function::Create(HelperFnType, GlobalValue::ExternalLinkage,
63 HelperName, M);
64
65 auto *WrapperFn = Function::Create(
66 WrapperFnType, GlobalValue::ExternalLinkage, WrapperName, M);
67 WrapperFn->setVisibility(WrapperVisibility);
68
69 auto *EntryBlock = BasicBlock::Create(M.getContext(), "entry", WrapperFn);
70 IRBuilder<> IB(EntryBlock);
71
72 std::vector<Value *> HelperArgs;
73 for (auto *Arg : HelperPrefixArgs)
74 HelperArgs.push_back(Arg);
75 for (auto &Arg : WrapperFn->args())
76 HelperArgs.push_back(&Arg);
77 auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
78 if (HelperFn->getReturnType()->isVoidTy())
79 IB.CreateRetVoid();
80 else
81 IB.CreateRet(HelperResult);
82
83 return WrapperFn;
84}
85
86class ORCPlatformSupport : public LLJIT::PlatformSupport {
87public:
88 ORCPlatformSupport(orc::LLJIT &J) : J(J) {}
89
90 Error initialize(orc::JITDylib &JD) override {
93 using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t);
94 enum dlopen_mode : int32_t {
95 ORC_RT_RTLD_LAZY = 0x1,
96 ORC_RT_RTLD_NOW = 0x2,
97 ORC_RT_RTLD_LOCAL = 0x4,
98 ORC_RT_RTLD_GLOBAL = 0x8
99 };
100
101 if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlopen_wrapper")) {
102 return J.getExecutionSession().callSPSWrapper<SPSDLOpenSig>(
103 *WrapperAddr, DSOHandles[&JD], JD.getName(),
104 int32_t(ORC_RT_RTLD_LAZY));
105 } else
106 return WrapperAddr.takeError();
107 }
108
109 Error deinitialize(orc::JITDylib &JD) override {
111 using SPSDLCloseSig = int32_t(SPSExecutorAddr);
112
113 if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlclose_wrapper")) {
114 int32_t result;
115 auto E = J.getExecutionSession().callSPSWrapper<SPSDLCloseSig>(
116 *WrapperAddr, result, DSOHandles[&JD]);
117 if (E)
118 return E;
119 else if (result)
120 return make_error<StringError>("dlclose failed",
122 DSOHandles.erase(&JD);
123 } else
124 return WrapperAddr.takeError();
125 return Error::success();
126 }
127
128private:
129 orc::LLJIT &J;
131};
132
133class GenericLLVMIRPlatformSupport;
134
135/// orc::Platform component of Generic LLVM IR Platform support.
136/// Just forwards calls to the GenericLLVMIRPlatformSupport class below.
137class GenericLLVMIRPlatform : public Platform {
138public:
139 GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
140 Error setupJITDylib(JITDylib &JD) override;
141 Error teardownJITDylib(JITDylib &JD) override;
143 const MaterializationUnit &MU) override;
144 Error notifyRemoving(ResourceTracker &RT) override {
145 // Noop -- Nothing to do (yet).
146 return Error::success();
147 }
148
149private:
150 GenericLLVMIRPlatformSupport &S;
151};
152
153/// This transform parses llvm.global_ctors to produce a single initialization
154/// function for the module, records the function, then deletes
155/// llvm.global_ctors.
156class GlobalCtorDtorScraper {
157public:
158 GlobalCtorDtorScraper(GenericLLVMIRPlatformSupport &PS,
159 StringRef InitFunctionPrefix,
160 StringRef DeInitFunctionPrefix)
161 : PS(PS), InitFunctionPrefix(InitFunctionPrefix),
162 DeInitFunctionPrefix(DeInitFunctionPrefix) {}
165
166private:
167 GenericLLVMIRPlatformSupport &PS;
168 StringRef InitFunctionPrefix;
169 StringRef DeInitFunctionPrefix;
170};
171
172/// Generic IR Platform Support
173///
174/// Scrapes llvm.global_ctors and llvm.global_dtors and replaces them with
175/// specially named 'init' and 'deinit'. Injects definitions / interposes for
176/// some runtime API, including __cxa_atexit, dlopen, and dlclose.
177class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
178public:
179 GenericLLVMIRPlatformSupport(LLJIT &J)
180 : J(J), InitFunctionPrefix(J.mangle("__orc_init_func.")),
181 DeInitFunctionPrefix(J.mangle("__orc_deinit_func.")) {
182
184 std::make_unique<GenericLLVMIRPlatform>(*this));
185
186 setInitTransform(J, GlobalCtorDtorScraper(*this, InitFunctionPrefix,
187 DeInitFunctionPrefix));
188
189 SymbolMap StdInterposes;
190
191 StdInterposes[J.mangleAndIntern("__lljit.platform_support_instance")] =
194 StdInterposes[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
195 JITEvaluatedSymbol(pointerToJITTargetAddress(registerCxaAtExitHelper),
197
198 cantFail(
199 J.getMainJITDylib().define(absoluteSymbols(std::move(StdInterposes))));
200 cantFail(setupJITDylib(J.getMainJITDylib()));
201 cantFail(J.addIRModule(J.getMainJITDylib(), createPlatformRuntimeModule()));
202 }
203
205
206 /// Adds a module that defines the __dso_handle global.
207 Error setupJITDylib(JITDylib &JD) {
208
209 // Add per-jitdylib standard interposes.
210 SymbolMap PerJDInterposes;
211 PerJDInterposes[J.mangleAndIntern("__lljit.run_atexits_helper")] =
214 PerJDInterposes[J.mangleAndIntern("__lljit.atexit_helper")] =
215 JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
217 cantFail(JD.define(absoluteSymbols(std::move(PerJDInterposes))));
218
219 auto Ctx = std::make_unique<LLVMContext>();
220 auto M = std::make_unique<Module>("__standard_lib", *Ctx);
221 M->setDataLayout(J.getDataLayout());
222
223 auto *Int64Ty = Type::getInt64Ty(*Ctx);
224 auto *DSOHandle = new GlobalVariable(
225 *M, Int64Ty, true, GlobalValue::ExternalLinkage,
226 ConstantInt::get(Int64Ty, reinterpret_cast<uintptr_t>(&JD)),
227 "__dso_handle");
228 DSOHandle->setVisibility(GlobalValue::DefaultVisibility);
229 DSOHandle->setInitializer(
231
232 auto *GenericIRPlatformSupportTy =
233 StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
234
235 auto *PlatformInstanceDecl = new GlobalVariable(
236 *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
237 nullptr, "__lljit.platform_support_instance");
238
239 auto *VoidTy = Type::getVoidTy(*Ctx);
240 addHelperAndWrapper(
241 *M, "__lljit_run_atexits", FunctionType::get(VoidTy, {}, false),
242 GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
243 {PlatformInstanceDecl, DSOHandle});
244
245 auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
246 auto *AtExitCallbackTy = FunctionType::get(VoidTy, {}, false);
247 auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
248 addHelperAndWrapper(*M, "atexit",
249 FunctionType::get(IntTy, {AtExitCallbackPtrTy}, false),
250 GlobalValue::HiddenVisibility, "__lljit.atexit_helper",
251 {PlatformInstanceDecl, DSOHandle});
252
253 return J.addIRModule(JD, ThreadSafeModule(std::move(M), std::move(Ctx)));
254 }
255
256 Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) {
257 auto &JD = RT.getJITDylib();
258 if (auto &InitSym = MU.getInitializerSymbol())
259 InitSymbols[&JD].add(InitSym, SymbolLookupFlags::WeaklyReferencedSymbol);
260 else {
261 // If there's no identified init symbol attached, but there is a symbol
262 // with the GenericIRPlatform::InitFunctionPrefix, then treat that as
263 // an init function. Add the symbol to both the InitSymbols map (which
264 // will trigger a lookup to materialize the module) and the InitFunctions
265 // map (which holds the names of the symbols to execute).
266 for (auto &KV : MU.getSymbols())
267 if ((*KV.first).startswith(InitFunctionPrefix)) {
268 InitSymbols[&JD].add(KV.first,
269 SymbolLookupFlags::WeaklyReferencedSymbol);
270 InitFunctions[&JD].add(KV.first);
271 } else if ((*KV.first).startswith(DeInitFunctionPrefix)) {
272 DeInitFunctions[&JD].add(KV.first);
273 }
274 }
275 return Error::success();
276 }
277
278 Error initialize(JITDylib &JD) override {
279 LLVM_DEBUG({
280 dbgs() << "GenericLLVMIRPlatformSupport getting initializers to run\n";
281 });
282 if (auto Initializers = getInitializers(JD)) {
284 { dbgs() << "GenericLLVMIRPlatformSupport running initializers\n"; });
285 for (auto InitFnAddr : *Initializers) {
286 LLVM_DEBUG({
287 dbgs() << " Running init " << formatv("{0:x16}", InitFnAddr)
288 << "...\n";
289 });
290 auto *InitFn = jitTargetAddressToFunction<void (*)()>(InitFnAddr);
291 InitFn();
292 }
293 } else
294 return Initializers.takeError();
295 return Error::success();
296 }
297
298 Error deinitialize(JITDylib &JD) override {
299 LLVM_DEBUG({
300 dbgs() << "GenericLLVMIRPlatformSupport getting deinitializers to run\n";
301 });
302 if (auto Deinitializers = getDeinitializers(JD)) {
303 LLVM_DEBUG({
304 dbgs() << "GenericLLVMIRPlatformSupport running deinitializers\n";
305 });
306 for (auto DeinitFnAddr : *Deinitializers) {
307 LLVM_DEBUG({
308 dbgs() << " Running deinit " << formatv("{0:x16}", DeinitFnAddr)
309 << "...\n";
310 });
311 auto *DeinitFn = jitTargetAddressToFunction<void (*)()>(DeinitFnAddr);
312 DeinitFn();
313 }
314 } else
315 return Deinitializers.takeError();
316
317 return Error::success();
318 }
319
320 void registerInitFunc(JITDylib &JD, SymbolStringPtr InitName) {
322 InitFunctions[&JD].add(InitName);
323 });
324 }
325
326 void registerDeInitFunc(JITDylib &JD, SymbolStringPtr DeInitName) {
328 [&]() { DeInitFunctions[&JD].add(DeInitName); });
329 }
330
331private:
332
334 if (auto Err = issueInitLookups(JD))
335 return std::move(Err);
336
338 std::vector<JITDylibSP> DFSLinkOrder;
339
340 if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
341 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
342 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
343 else
344 return DFSLinkOrderOrErr.takeError();
345
346 for (auto &NextJD : DFSLinkOrder) {
347 auto IFItr = InitFunctions.find(NextJD.get());
348 if (IFItr != InitFunctions.end()) {
349 LookupSymbols[NextJD.get()] = std::move(IFItr->second);
350 InitFunctions.erase(IFItr);
351 }
352 }
353 return Error::success();
354 }))
355 return std::move(Err);
356
357 LLVM_DEBUG({
358 dbgs() << "JITDylib init order is [ ";
359 for (auto &JD : llvm::reverse(DFSLinkOrder))
360 dbgs() << "\"" << JD->getName() << "\" ";
361 dbgs() << "]\n";
362 dbgs() << "Looking up init functions:\n";
363 for (auto &KV : LookupSymbols)
364 dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
365 });
366
367 auto &ES = getExecutionSession();
368 auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
369
370 if (!LookupResult)
371 return LookupResult.takeError();
372
373 std::vector<JITTargetAddress> Initializers;
374 while (!DFSLinkOrder.empty()) {
375 auto &NextJD = *DFSLinkOrder.back();
376 DFSLinkOrder.pop_back();
377 auto InitsItr = LookupResult->find(&NextJD);
378 if (InitsItr == LookupResult->end())
379 continue;
380 for (auto &KV : InitsItr->second)
381 Initializers.push_back(KV.second.getAddress());
382 }
383
384 return Initializers;
385 }
386
387 Expected<std::vector<JITTargetAddress>> getDeinitializers(JITDylib &JD) {
388 auto &ES = getExecutionSession();
389
390 auto LLJITRunAtExits = J.mangleAndIntern("__lljit_run_atexits");
391
393 std::vector<JITDylibSP> DFSLinkOrder;
394
395 if (auto Err = ES.runSessionLocked([&]() -> Error {
396 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
397 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
398 else
399 return DFSLinkOrderOrErr.takeError();
400
401 for (auto &NextJD : DFSLinkOrder) {
402 auto &JDLookupSymbols = LookupSymbols[NextJD.get()];
403 auto DIFItr = DeInitFunctions.find(NextJD.get());
404 if (DIFItr != DeInitFunctions.end()) {
405 LookupSymbols[NextJD.get()] = std::move(DIFItr->second);
406 DeInitFunctions.erase(DIFItr);
407 }
408 JDLookupSymbols.add(LLJITRunAtExits,
409 SymbolLookupFlags::WeaklyReferencedSymbol);
410 }
411 return Error::success();
412 }))
413 return std::move(Err);
414
415 LLVM_DEBUG({
416 dbgs() << "JITDylib deinit order is [ ";
417 for (auto &JD : DFSLinkOrder)
418 dbgs() << "\"" << JD->getName() << "\" ";
419 dbgs() << "]\n";
420 dbgs() << "Looking up deinit functions:\n";
421 for (auto &KV : LookupSymbols)
422 dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
423 });
424
425 auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
426
427 if (!LookupResult)
428 return LookupResult.takeError();
429
430 std::vector<JITTargetAddress> DeInitializers;
431 for (auto &NextJD : DFSLinkOrder) {
432 auto DeInitsItr = LookupResult->find(NextJD.get());
433 assert(DeInitsItr != LookupResult->end() &&
434 "Every JD should have at least __lljit_run_atexits");
435
436 auto RunAtExitsItr = DeInitsItr->second.find(LLJITRunAtExits);
437 if (RunAtExitsItr != DeInitsItr->second.end())
438 DeInitializers.push_back(RunAtExitsItr->second.getAddress());
439
440 for (auto &KV : DeInitsItr->second)
441 if (KV.first != LLJITRunAtExits)
442 DeInitializers.push_back(KV.second.getAddress());
443 }
444
445 return DeInitializers;
446 }
447
448 /// Issue lookups for all init symbols required to initialize JD (and any
449 /// JITDylibs that it depends on).
450 Error issueInitLookups(JITDylib &JD) {
451 DenseMap<JITDylib *, SymbolLookupSet> RequiredInitSymbols;
452 std::vector<JITDylibSP> DFSLinkOrder;
453
454 if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
455 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
456 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
457 else
458 return DFSLinkOrderOrErr.takeError();
459
460 for (auto &NextJD : DFSLinkOrder) {
461 auto ISItr = InitSymbols.find(NextJD.get());
462 if (ISItr != InitSymbols.end()) {
463 RequiredInitSymbols[NextJD.get()] = std::move(ISItr->second);
464 InitSymbols.erase(ISItr);
465 }
466 }
467 return Error::success();
468 }))
469 return Err;
470
471 return Platform::lookupInitSymbols(getExecutionSession(),
472 RequiredInitSymbols)
473 .takeError();
474 }
475
476 static void registerCxaAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
477 void *DSOHandle) {
478 LLVM_DEBUG({
479 dbgs() << "Registering cxa atexit function " << (void *)F << " for JD "
480 << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
481 });
482 static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
483 F, Ctx, DSOHandle);
484 }
485
486 static void registerAtExitHelper(void *Self, void *DSOHandle, void (*F)()) {
487 LLVM_DEBUG({
488 dbgs() << "Registering atexit function " << (void *)F << " for JD "
489 << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
490 });
491 static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
492 reinterpret_cast<void (*)(void *)>(F), nullptr, DSOHandle);
493 }
494
495 static void runAtExitsHelper(void *Self, void *DSOHandle) {
496 LLVM_DEBUG({
497 dbgs() << "Running atexit functions for JD "
498 << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
499 });
500 static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.runAtExits(
501 DSOHandle);
502 }
503
504 // Constructs an LLVM IR module containing platform runtime globals,
505 // functions, and interposes.
506 ThreadSafeModule createPlatformRuntimeModule() {
507 auto Ctx = std::make_unique<LLVMContext>();
508 auto M = std::make_unique<Module>("__standard_lib", *Ctx);
509 M->setDataLayout(J.getDataLayout());
510
511 auto *GenericIRPlatformSupportTy =
512 StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
513
514 auto *PlatformInstanceDecl = new GlobalVariable(
515 *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
516 nullptr, "__lljit.platform_support_instance");
517
518 auto *Int8Ty = Type::getInt8Ty(*Ctx);
519 auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
520 auto *VoidTy = Type::getVoidTy(*Ctx);
521 auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
522 auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
523 auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
524
525 addHelperAndWrapper(
526 *M, "__cxa_atexit",
527 FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
528 false),
529 GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
530 {PlatformInstanceDecl});
531
532 return ThreadSafeModule(std::move(M), std::move(Ctx));
533 }
534
535 LLJIT &J;
536 std::string InitFunctionPrefix;
537 std::string DeInitFunctionPrefix;
541 ItaniumCXAAtExitSupport AtExitMgr;
542};
543
544Error GenericLLVMIRPlatform::setupJITDylib(JITDylib &JD) {
545 return S.setupJITDylib(JD);
546}
547
548Error GenericLLVMIRPlatform::teardownJITDylib(JITDylib &JD) {
549 return Error::success();
550}
551
552Error GenericLLVMIRPlatform::notifyAdding(ResourceTracker &RT,
553 const MaterializationUnit &MU) {
554 return S.notifyAdding(RT, MU);
555}
556
558GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
560 auto Err = TSM.withModuleDo([&](Module &M) -> Error {
561 auto &Ctx = M.getContext();
562 auto *GlobalCtors = M.getNamedGlobal("llvm.global_ctors");
563 auto *GlobalDtors = M.getNamedGlobal("llvm.global_dtors");
564
565 auto RegisterCOrDtors = [&](GlobalVariable *GlobalCOrDtors,
566 bool isCtor) -> Error {
567 // If there's no llvm.global_c/dtor or it's just a decl then skip.
568 if (!GlobalCOrDtors || GlobalCOrDtors->isDeclaration())
569 return Error::success();
570 std::string InitOrDeInitFunctionName;
571 if (isCtor)
572 raw_string_ostream(InitOrDeInitFunctionName)
573 << InitFunctionPrefix << M.getModuleIdentifier();
574 else
575 raw_string_ostream(InitOrDeInitFunctionName)
576 << DeInitFunctionPrefix << M.getModuleIdentifier();
577
578 MangleAndInterner Mangle(PS.getExecutionSession(), M.getDataLayout());
579 auto InternedInitOrDeInitName = Mangle(InitOrDeInitFunctionName);
580 if (auto Err = R.defineMaterializing(
581 {{InternedInitOrDeInitName, JITSymbolFlags::Callable}}))
582 return Err;
583
584 auto *InitOrDeInitFunc = Function::Create(
585 FunctionType::get(Type::getVoidTy(Ctx), {}, false),
586 GlobalValue::ExternalLinkage, InitOrDeInitFunctionName, &M);
587 InitOrDeInitFunc->setVisibility(GlobalValue::HiddenVisibility);
588 std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
589 auto COrDtors = isCtor ? getConstructors(M) : getDestructors(M);
590
591 for (auto E : COrDtors)
592 InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
593 llvm::sort(InitsOrDeInits, llvm::less_second());
594
595 auto *InitOrDeInitFuncEntryBlock =
596 BasicBlock::Create(Ctx, "entry", InitOrDeInitFunc);
597 IRBuilder<> IB(InitOrDeInitFuncEntryBlock);
598 for (auto &KV : InitsOrDeInits)
599 IB.CreateCall(KV.first);
600 IB.CreateRetVoid();
601
602 if (isCtor)
603 PS.registerInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
604 else
605 PS.registerDeInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
606
607 GlobalCOrDtors->eraseFromParent();
608 return Error::success();
609 };
610
611 if (auto Err = RegisterCOrDtors(GlobalCtors, true))
612 return Err;
613 if (auto Err = RegisterCOrDtors(GlobalDtors, false))
614 return Err;
615
616 return Error::success();
617 });
618
619 if (Err)
620 return std::move(Err);
621
622 return std::move(TSM);
623}
624
625/// Inactive Platform Support
626///
627/// Explicitly disables platform support. JITDylibs are not scanned for special
628/// init/deinit symbols. No runtime API interposes are injected.
629class InactivePlatformSupport : public LLJIT::PlatformSupport {
630public:
631 InactivePlatformSupport() = default;
632
633 Error initialize(JITDylib &JD) override {
634 LLVM_DEBUG(dbgs() << "InactivePlatformSupport: no initializers running for "
635 << JD.getName() << "\n");
636 return Error::success();
637 }
638
639 Error deinitialize(JITDylib &JD) override {
641 dbgs() << "InactivePlatformSupport: no deinitializers running for "
642 << JD.getName() << "\n");
643 return Error::success();
644 }
645};
646
647} // end anonymous namespace
648
649namespace llvm {
650namespace orc {
651
654 J.InitHelperTransformLayer->setTransform(std::move(T));
655}
656
658
660
661 LLVM_DEBUG(dbgs() << "Preparing to create LLJIT instance...\n");
662
663 if (!JTMB) {
664 LLVM_DEBUG({
665 dbgs() << " No explicitly set JITTargetMachineBuilder. "
666 "Detecting host...\n";
667 });
668 if (auto JTMBOrErr = JITTargetMachineBuilder::detectHost())
669 JTMB = std::move(*JTMBOrErr);
670 else
671 return JTMBOrErr.takeError();
672 }
673
674 LLVM_DEBUG({
675 dbgs() << " JITTargetMachineBuilder is "
676 << JITTargetMachineBuilderPrinter(*JTMB, " ")
677 << " Pre-constructed ExecutionSession: " << (ES ? "Yes" : "No")
678 << "\n"
679 << " DataLayout: ";
680 if (DL)
681 dbgs() << DL->getStringRepresentation() << "\n";
682 else
683 dbgs() << "None (will be created by JITTargetMachineBuilder)\n";
684
685 dbgs() << " Custom object-linking-layer creator: "
686 << (CreateObjectLinkingLayer ? "Yes" : "No") << "\n"
687 << " Custom compile-function creator: "
688 << (CreateCompileFunction ? "Yes" : "No") << "\n"
689 << " Custom platform-setup function: "
690 << (SetUpPlatform ? "Yes" : "No") << "\n"
691 << " Number of compile threads: " << NumCompileThreads;
692 if (!NumCompileThreads)
693 dbgs() << " (code will be compiled on the execution thread)\n";
694 else
695 dbgs() << "\n";
696 });
697
698 // If neither ES nor EPC has been set then create an EPC instance.
699 if (!ES && !EPC) {
700 LLVM_DEBUG({
701 dbgs() << "ExecutorProcessControl not specified, "
702 "Creating SelfExecutorProcessControl instance\n";
703 });
704 if (auto EPCOrErr = SelfExecutorProcessControl::Create())
705 EPC = std::move(*EPCOrErr);
706 else
707 return EPCOrErr.takeError();
708 } else
709 LLVM_DEBUG({
710 dbgs() << "Using explicitly specified ExecutorProcessControl instance "
711 << EPC.get() << "\n";
712 });
713
714 // If the client didn't configure any linker options then auto-configure the
715 // JIT linker.
716 if (!CreateObjectLinkingLayer) {
717 auto &TT = JTMB->getTargetTriple();
718 bool UseJITLink = false;
719 switch (TT.getArch()) {
720 case Triple::riscv64:
722 UseJITLink = true;
723 break;
724 case Triple::aarch64:
725 UseJITLink = !TT.isOSBinFormatCOFF();
726 break;
727 case Triple::x86_64:
728 UseJITLink = TT.isOSBinFormatMachO();
729 break;
730 default:
731 break;
732 }
733 if (UseJITLink) {
734 JTMB->setRelocationModel(Reloc::PIC_);
735 JTMB->setCodeModel(CodeModel::Small);
736 CreateObjectLinkingLayer =
738 const Triple &) -> Expected<std::unique_ptr<ObjectLayer>> {
739 auto ObjLinkingLayer = std::make_unique<ObjectLinkingLayer>(ES);
740 if (auto EHFrameRegistrar = EPCEHFrameRegistrar::Create(ES))
741 ObjLinkingLayer->addPlugin(
742 std::make_unique<EHFrameRegistrationPlugin>(
743 ES, std::move(*EHFrameRegistrar)));
744 else
745 return EHFrameRegistrar.takeError();
746 return std::move(ObjLinkingLayer);
747 };
748 }
749 }
750
751 return Error::success();
752}
753
755 if (CompileThreads)
756 CompileThreads->wait();
757 if (auto Err = ES->endSession())
758 ES->reportError(std::move(Err));
759}
760
762 assert(TSM && "Can not add null module");
763
764 if (auto Err =
765 TSM.withModuleDo([&](Module &M) { return applyDataLayout(M); }))
766 return Err;
767
768 return InitHelperTransformLayer->add(std::move(RT), std::move(TSM));
769}
770
772 return addIRModule(JD.getDefaultResourceTracker(), std::move(TSM));
773}
774
776 std::unique_ptr<MemoryBuffer> Obj) {
777 assert(Obj && "Can not add null object");
778
779 return ObjTransformLayer->add(std::move(RT), std::move(Obj));
780}
781
782Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
783 return addObjectFile(JD.getDefaultResourceTracker(), std::move(Obj));
784}
785
788 if (auto Sym = ES->lookup(
790 Name))
791 return ExecutorAddr(Sym->getAddress());
792 else
793 return Sym.takeError();
794}
795
798
799 // If the config state provided an ObjectLinkingLayer factory then use it.
801 return S.CreateObjectLinkingLayer(ES, S.JTMB->getTargetTriple());
802
803 // Otherwise default to creating an RTDyldObjectLinkingLayer that constructs
804 // a new SectionMemoryManager for each object.
805 auto GetMemMgr = []() { return std::make_unique<SectionMemoryManager>(); };
806 auto Layer =
807 std::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
808
809 if (S.JTMB->getTargetTriple().isOSBinFormatCOFF()) {
810 Layer->setOverrideObjectFlagsWithResponsibilityFlags(true);
811 Layer->setAutoClaimResponsibilityForObjectSymbols(true);
812 }
813
814 if (S.JTMB->getTargetTriple().isOSBinFormatELF() &&
815 (S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64 ||
816 S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64le))
817 Layer->setAutoClaimResponsibilityForObjectSymbols(true);
818
819 // FIXME: Explicit conversion to std::unique_ptr<ObjectLayer> added to silence
820 // errors from some GCC / libstdc++ bots. Remove this conversion (i.e.
821 // just return ObjLinkingLayer) once those bots are upgraded.
822 return std::unique_ptr<ObjectLayer>(std::move(Layer));
823}
824
828
829 /// If there is a custom compile function creator set then use it.
831 return S.CreateCompileFunction(std::move(JTMB));
832
833 // Otherwise default to creating a SimpleCompiler, or ConcurrentIRCompiler,
834 // depending on the number of threads requested.
835 if (S.NumCompileThreads > 0)
836 return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
837
838 auto TM = JTMB.createTargetMachine();
839 if (!TM)
840 return TM.takeError();
841
842 return std::make_unique<TMOwningSimpleCompiler>(std::move(*TM));
843}
844
846 : DL(""), TT(S.JTMB->getTargetTriple()) {
847
849
850 assert(!(S.EPC && S.ES) && "EPC and ES should not both be set");
851
852 if (S.EPC) {
853 ES = std::make_unique<ExecutionSession>(std::move(S.EPC));
854 } else if (S.ES)
855 ES = std::move(S.ES);
856 else {
857 if (auto EPC = SelfExecutorProcessControl::Create()) {
858 ES = std::make_unique<ExecutionSession>(std::move(*EPC));
859 } else {
860 Err = EPC.takeError();
861 return;
862 }
863 }
864
865 if (auto MainOrErr = this->ES->createJITDylib("main"))
866 Main = &*MainOrErr;
867 else {
868 Err = MainOrErr.takeError();
869 return;
870 }
871
872 if (S.DL)
873 DL = std::move(*S.DL);
874 else if (auto DLOrErr = S.JTMB->getDefaultDataLayoutForTarget())
875 DL = std::move(*DLOrErr);
876 else {
877 Err = DLOrErr.takeError();
878 return;
879 }
880
881 auto ObjLayer = createObjectLinkingLayer(S, *ES);
882 if (!ObjLayer) {
883 Err = ObjLayer.takeError();
884 return;
885 }
886 ObjLinkingLayer = std::move(*ObjLayer);
888 std::make_unique<ObjectTransformLayer>(*ES, *ObjLinkingLayer);
889
890 {
891 auto CompileFunction = createCompileFunction(S, std::move(*S.JTMB));
892 if (!CompileFunction) {
893 Err = CompileFunction.takeError();
894 return;
895 }
896 CompileLayer = std::make_unique<IRCompileLayer>(
897 *ES, *ObjTransformLayer, std::move(*CompileFunction));
898 TransformLayer = std::make_unique<IRTransformLayer>(*ES, *CompileLayer);
900 std::make_unique<IRTransformLayer>(*ES, *TransformLayer);
901 }
902
903 if (S.NumCompileThreads > 0) {
904 InitHelperTransformLayer->setCloneToNewContextOnEmit(true);
906 std::make_unique<ThreadPool>(hardware_concurrency(S.NumCompileThreads));
907 ES->setDispatchTask([this](std::unique_ptr<Task> T) {
908 // FIXME: We should be able to use move-capture here, but ThreadPool's
909 // AsyncTaskTys are std::functions rather than unique_functions
910 // (because MSVC's std::packaged_tasks don't support move-only types).
911 // Fix this when all the above gets sorted out.
912 CompileThreads->async([UnownedT = T.release()]() mutable {
913 std::unique_ptr<Task> T(UnownedT);
914 T->run();
915 });
916 });
917 }
918
919 if (S.SetUpPlatform)
920 Err = S.SetUpPlatform(*this);
921 else
923}
924
925std::string LLJIT::mangle(StringRef UnmangledName) const {
926 std::string MangledName;
927 {
928 raw_string_ostream MangledNameStream(MangledName);
929 Mangler::getNameWithPrefix(MangledNameStream, UnmangledName, DL);
930 }
931 return MangledName;
932}
933
935 if (M.getDataLayout().isDefault())
936 M.setDataLayout(DL);
937
938 if (M.getDataLayout() != DL)
939 return make_error<StringError>(
940 "Added modules have incompatible data layouts: " +
941 M.getDataLayout().getStringRepresentation() + " (module) vs " +
942 DL.getStringRepresentation() + " (jit)",
944
945 return Error::success();
946}
947
950 { dbgs() << "Setting up orc platform support for LLJIT\n"; });
951 J.setPlatformSupport(std::make_unique<ORCPlatformSupport>(J));
952 return Error::success();
953}
954
957 { dbgs() << "Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
958 J.setPlatformSupport(std::make_unique<GenericLLVMIRPlatformSupport>(J));
959}
960
963 { dbgs() << "Explicitly deactivated platform support for LLJIT\n"; });
964 J.setPlatformSupport(std::make_unique<InactivePlatformSupport>());
965 return Error::success();
966}
967
970 return Err;
971 TT = JTMB->getTargetTriple();
972 return Error::success();
973}
974
976 assert(TSM && "Can not add null module");
977
978 if (auto Err = TSM.withModuleDo(
979 [&](Module &M) -> Error { return applyDataLayout(M); }))
980 return Err;
981
982 return CODLayer->add(JD, std::move(TSM));
983}
984
985LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
986
987 // If LLJIT construction failed then bail out.
988 if (Err)
989 return;
990
992
993 /// Take/Create the lazy-compile callthrough manager.
994 if (S.LCTMgr)
995 LCTMgr = std::move(S.LCTMgr);
996 else {
997 if (auto LCTMgrOrErr = createLocalLazyCallThroughManager(
999 LCTMgr = std::move(*LCTMgrOrErr);
1000 else {
1001 Err = LCTMgrOrErr.takeError();
1002 return;
1003 }
1004 }
1005
1006 // Take/Create the indirect stubs manager builder.
1007 auto ISMBuilder = std::move(S.ISMBuilder);
1008
1009 // If none was provided, try to build one.
1010 if (!ISMBuilder)
1012
1013 // No luck. Bail out.
1014 if (!ISMBuilder) {
1015 Err = make_error<StringError>("Could not construct "
1016 "IndirectStubsManagerBuilder for target " +
1017 S.TT.str(),
1019 return;
1020 }
1021
1022 // Create the COD layer.
1023 CODLayer = std::make_unique<CompileOnDemandLayer>(
1024 *ES, *InitHelperTransformLayer, *LCTMgr, std::move(ISMBuilder));
1025
1026 if (S.NumCompileThreads > 0)
1027 CODLayer->setCloneToNewContextOnEmit(true);
1028}
1029
1030// In-process LLJIT uses eh-frame section wrappers via EPC, so we need to force
1031// them to be linked in.
1035}
1036
1037} // End namespace orc.
1038} // End namespace llvm.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
for(auto &MBB :MF)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ATTRIBUTE_USED
Definition: Compiler.h:139
#define LLVM_DEBUG(X)
Definition: Debug.h:101
std::string Name
#define _
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
if(VerifyEach)
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),...
Definition: ArrayRef.h:41
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:105
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.
Definition: Constants.cpp:888
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:246
Helper for Errors used as out-parameters.
Definition: Error.h:1104
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
static ErrorSuccess success()
Create a success value.
Definition: Error.h:330
Tagged union holding either a T or a Error.
Definition: Error.h:470
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)
Definition: Function.h:136
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:275
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:62
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:468
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2558
Represents a symbol that has been evaluated to an address already.
Definition: JITSymbol.h:229
Flags for symbols in the JIT.
Definition: JITSymbol.h:74
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition: Mangler.cpp:119
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:651
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:533
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:688
@ loongarch64
Definition: Triple.h:62
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:356
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:680
const std::string & str() const
Definition: Triple.h:415
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
static Expected< std::unique_ptr< EPCEHFrameRegistrar > > Create(ExecutionSession &ES, std::optional< ExecutorAddr > RegistrationFunctionsDylib=std::nullopt)
Create from a ExecutorProcessControl instance alone.
An ExecutionSession represents a running JIT program.
Definition: Core.h:1373
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
Definition: Core.h:1430
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition: Core.h:1621
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition: Core.h:1437
Represents an address in the executor process.
uint64_t getValue() const
An interface for Itanium __cxa_atexit interposer implementations.
Represents a JIT'd dynamic library.
Definition: Core.h:962
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition: Core.h:1816
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...
Definition: Core.cpp:2004
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:661
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.
Definition: LLJIT.cpp:659
ObjectLinkingLayerCreator CreateObjectLinkingLayer
Definition: LLJIT.h:267
std::unique_ptr< ExecutionSession > ES
Definition: LLJIT.h:264
CompileFunctionCreator CreateCompileFunction
Definition: LLJIT.h:268
std::unique_ptr< ExecutorProcessControl > EPC
Definition: LLJIT.h:263
std::optional< DataLayout > DL
Definition: LLJIT.h:266
std::optional< JITTargetMachineBuilder > JTMB
Definition: LLJIT.h:265
PlatformSetupFunction SetUpPlatform
Definition: LLJIT.h:269
Initializer support for LLJIT.
Definition: LLJIT.h:44
virtual Error deinitialize(JITDylib &JD)=0
virtual Error initialize(JITDylib &JD)=0
static void setInitTransform(LLJIT &J, IRTransformLayer::TransformFunction T)
Definition: LLJIT.cpp:652
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
Definition: LLJIT.h:37
static Expected< std::unique_ptr< ObjectLayer > > createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES)
Definition: LLJIT.cpp:797
void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)
Set the PlatformSupport instance.
Definition: LLJIT.h:141
std::unique_ptr< ExecutionSession > ES
Definition: LLJIT.h:202
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
Definition: LLJIT.cpp:845
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Definition: LLJIT.cpp:775
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
Definition: LLJIT.h:71
const DataLayout & getDataLayout() const
Returns a reference to the DataLayout for this instance.
Definition: LLJIT.h:68
std::unique_ptr< ObjectTransformLayer > ObjTransformLayer
Definition: LLJIT.h:212
virtual ~LLJIT()
Destruct this instance.
Definition: LLJIT.cpp:754
std::string mangle(StringRef UnmangledName) const
Returns a linker-mangled version of UnmangledName.
Definition: LLJIT.cpp:925
JITDylib * Main
Definition: LLJIT.h:205
Expected< ExecutorAddr > lookup(JITDylib &JD, StringRef UnmangledName)
Look up a symbol in JITDylib JD based on its IR symbol name.
Definition: LLJIT.h:131
std::unique_ptr< IRTransformLayer > InitHelperTransformLayer
Definition: LLJIT.h:215
std::unique_ptr< IRCompileLayer > CompileLayer
Definition: LLJIT.h:213
const Triple & getTargetTriple() const
Returns a reference to the triple for this instance.
Definition: LLJIT.h:65
Expected< ExecutorAddr > lookupLinkerMangled(JITDylib &JD, SymbolStringPtr Name)
Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on thei...
Definition: LLJIT.cpp:786
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
Definition: LLJIT.cpp:826
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition: LLJIT.h:62
std::unique_ptr< IRTransformLayer > TransformLayer
Definition: LLJIT.h:214
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Definition: LLJIT.h:184
DataLayout DL
Definition: LLJIT.h:207
friend void setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition: LLJIT.cpp:955
Error applyDataLayout(Module &M)
Definition: LLJIT.cpp:934
std::unique_ptr< ThreadPool > CompileThreads
Definition: LLJIT.h:209
std::unique_ptr< ObjectLayer > ObjLinkingLayer
Definition: LLJIT.h:211
Triple TT
Definition: LLJIT.h:208
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
Definition: LLJIT.cpp:761
ExecutorAddr LazyCompileFailureAddr
Definition: LLJIT.h:404
std::unique_ptr< LazyCallThroughManager > LCTMgr
Definition: LLJIT.h:405
IndirectStubsManagerBuilderFunction ISMBuilder
Definition: LLJIT.h:406
Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
Definition: LLJIT.cpp:975
Mangles symbol names then uniques them in the context of an ExecutionSession.
Definition: Mangling.h:26
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:524
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Definition: Core.h:673
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
Definition: Core.h:703
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
Definition: Core.h:706
Platforms set up standard symbols and mediate interactions between dynamic initializers (e....
Definition: Core.h:1317
virtual Error teardownJITDylib(JITDylib &JD)=0
This method will be called outside the session lock each time a JITDylib is removed to allow the Plat...
virtual Error notifyRemoving(ResourceTracker &RT)=0
This method will be called under the ExecutionSession lock when a ResourceTracker is removed.
static Expected< DenseMap< JITDylib *, SymbolMap > > lookupInitSymbols(ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
A utility function for looking up initializer symbols.
Definition: Core.cpp:1792
virtual Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU)=0
This method will be called under the ExecutionSession lock each time a MaterializationUnit is added t...
virtual Error setupJITDylib(JITDylib &JD)=0
This method will be called outside the session lock each time a JITDylib is created (unless it is cre...
API to remove / transfer ownership of JIT resources.
Definition: Core.h:53
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:68
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.
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.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:642
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...
Definition: Core.h:163
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:771
Error setUpOrcPlatform(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
Definition: LLJIT.cpp:948
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
LLVM_ATTRIBUTE_USED void linkComponents()
Definition: LLJIT.cpp:1032
std::function< std::unique_ptr< IndirectStubsManager >()> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
void setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition: LLJIT.cpp:955
Error setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
Definition: LLJIT.cpp:961
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
Definition: Threading.h:185
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...
Definition: Error.cpp:79
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:511
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1744
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
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.
Definition: Error.h:745
JITTargetAddress pointerToJITTargetAddress(T *Ptr)
Convert a pointer to a JITTargetAddress.
Definition: JITSymbol.h:69
Function object to check whether the second component of a container supported by std::get (like std:...
Definition: STLExtras.h:1546