LLVM 22.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
10
12#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
27#include "llvm/IR/IRBuilder.h"
28#include "llvm/IR/Mangler.h"
29#include "llvm/IR/Module.h"
31
32#define DEBUG_TYPE "orc"
33
34using namespace llvm;
35using namespace llvm::orc;
36
37namespace {
38
39/// Adds helper function decls and wrapper functions that call the helper with
40/// some additional prefix arguments.
41///
42/// E.g. For wrapper "foo" with type i8(i8, i64), helper "bar", and prefix
43/// args i32 4 and i16 12345, this function will add:
44///
45/// declare i8 @bar(i32, i16, i8, i64)
46///
47/// define i8 @foo(i8, i64) {
48/// entry:
49/// %2 = call i8 @bar(i32 4, i16 12345, i8 %0, i64 %1)
50/// ret i8 %2
51/// }
52///
53Function *addHelperAndWrapper(Module &M, StringRef WrapperName,
54 FunctionType *WrapperFnType,
55 GlobalValue::VisibilityTypes WrapperVisibility,
56 StringRef HelperName,
57 ArrayRef<Value *> HelperPrefixArgs) {
58 std::vector<Type *> HelperArgTypes;
59 for (auto *Arg : HelperPrefixArgs)
60 HelperArgTypes.push_back(Arg->getType());
61 llvm::append_range(HelperArgTypes, WrapperFnType->params());
62 auto *HelperFnType =
63 FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes, false);
64 auto *HelperFn = Function::Create(HelperFnType, GlobalValue::ExternalLinkage,
65 HelperName, M);
66
67 auto *WrapperFn = Function::Create(
68 WrapperFnType, GlobalValue::ExternalLinkage, WrapperName, M);
69 WrapperFn->setVisibility(WrapperVisibility);
70
71 auto *EntryBlock = BasicBlock::Create(M.getContext(), "entry", WrapperFn);
72 IRBuilder<> IB(EntryBlock);
73
74 std::vector<Value *> HelperArgs;
75 llvm::append_range(HelperArgs, HelperPrefixArgs);
76 for (auto &Arg : WrapperFn->args())
77 HelperArgs.push_back(&Arg);
78 auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
79 if (HelperFn->getReturnType()->isVoidTy())
80 IB.CreateRetVoid();
81 else
82 IB.CreateRet(HelperResult);
83
84 return WrapperFn;
85}
86
87class GenericLLVMIRPlatformSupport;
88
89/// orc::Platform component of Generic LLVM IR Platform support.
90/// Just forwards calls to the GenericLLVMIRPlatformSupport class below.
91class GenericLLVMIRPlatform : public Platform {
92public:
93 GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
94 Error setupJITDylib(JITDylib &JD) override;
95 Error teardownJITDylib(JITDylib &JD) override;
97 const MaterializationUnit &MU) override;
99 // Noop -- Nothing to do (yet).
100 return Error::success();
101 }
102
103private:
104 GenericLLVMIRPlatformSupport &S;
105};
106
107/// This transform parses llvm.global_ctors to produce a single initialization
108/// function for the module, records the function, then deletes
109/// llvm.global_ctors.
110class GlobalCtorDtorScraper {
111public:
112 GlobalCtorDtorScraper(GenericLLVMIRPlatformSupport &PS,
113 StringRef InitFunctionPrefix,
114 StringRef DeInitFunctionPrefix)
115 : PS(PS), InitFunctionPrefix(InitFunctionPrefix),
116 DeInitFunctionPrefix(DeInitFunctionPrefix) {}
119
120private:
121 GenericLLVMIRPlatformSupport &PS;
122 StringRef InitFunctionPrefix;
123 StringRef DeInitFunctionPrefix;
124};
125
126/// Generic IR Platform Support
127///
128/// Scrapes llvm.global_ctors and llvm.global_dtors and replaces them with
129/// specially named 'init' and 'deinit'. Injects definitions / interposes for
130/// some runtime API, including __cxa_atexit, dlopen, and dlclose.
131class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
132public:
133 GenericLLVMIRPlatformSupport(LLJIT &J, JITDylib &PlatformJD)
134 : J(J), InitFunctionPrefix(J.mangle("__orc_init_func.")),
135 DeInitFunctionPrefix(J.mangle("__orc_deinit_func.")) {
136
138 std::make_unique<GenericLLVMIRPlatform>(*this));
139
140 setInitTransform(J, GlobalCtorDtorScraper(*this, InitFunctionPrefix,
141 DeInitFunctionPrefix));
142
143 SymbolMap StdInterposes;
144
145 StdInterposes[J.mangleAndIntern("__lljit.platform_support_instance")] = {
147 StdInterposes[J.mangleAndIntern("__lljit.cxa_atexit_helper")] = {
148 ExecutorAddr::fromPtr(registerCxaAtExitHelper), JITSymbolFlags()};
149
150 cantFail(PlatformJD.define(absoluteSymbols(std::move(StdInterposes))));
151 cantFail(setupJITDylib(PlatformJD));
152 cantFail(J.addIRModule(PlatformJD, createPlatformRuntimeModule()));
153 }
154
156
157 /// Adds a module that defines the __dso_handle global.
158 Error setupJITDylib(JITDylib &JD) {
159
160 // Add per-jitdylib standard interposes.
161 SymbolMap PerJDInterposes;
162 PerJDInterposes[J.mangleAndIntern("__lljit.run_atexits_helper")] = {
163 ExecutorAddr::fromPtr(runAtExitsHelper), JITSymbolFlags()};
164 PerJDInterposes[J.mangleAndIntern("__lljit.atexit_helper")] = {
165 ExecutorAddr::fromPtr(registerAtExitHelper), JITSymbolFlags()};
166 cantFail(JD.define(absoluteSymbols(std::move(PerJDInterposes))));
167
168 auto Ctx = std::make_unique<LLVMContext>();
169 auto M = std::make_unique<Module>("__standard_lib", *Ctx);
170 M->setDataLayout(J.getDataLayout());
171
172 auto *Int64Ty = Type::getInt64Ty(*Ctx);
173 auto *DSOHandle = new GlobalVariable(
174 *M, Int64Ty, true, GlobalValue::ExternalLinkage,
175 ConstantInt::get(Int64Ty, reinterpret_cast<uintptr_t>(&JD)),
176 "__dso_handle");
177 DSOHandle->setVisibility(GlobalValue::DefaultVisibility);
178 DSOHandle->setInitializer(
179 ConstantInt::get(Int64Ty, ExecutorAddr::fromPtr(&JD).getValue()));
180
181 auto *GenericIRPlatformSupportTy =
182 StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
183
184 auto *PlatformInstanceDecl = new GlobalVariable(
185 *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
186 nullptr, "__lljit.platform_support_instance");
187
188 auto *VoidTy = Type::getVoidTy(*Ctx);
189 addHelperAndWrapper(
190 *M, "__lljit_run_atexits", FunctionType::get(VoidTy, {}, false),
191 GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
192 {PlatformInstanceDecl, DSOHandle});
193
194 auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
195 auto *AtExitCallbackPtrTy = PointerType::getUnqual(*Ctx);
196 auto *AtExit = addHelperAndWrapper(
197 *M, "atexit", FunctionType::get(IntTy, {AtExitCallbackPtrTy}, false),
198 GlobalValue::HiddenVisibility, "__lljit.atexit_helper",
199 {PlatformInstanceDecl, DSOHandle});
200 Attribute::AttrKind AtExitExtAttr =
201 TargetLibraryInfo::getExtAttrForI32Return(J.getTargetTriple());
202 if (AtExitExtAttr != Attribute::None)
203 AtExit->addRetAttr(AtExitExtAttr);
204
205 return J.addIRModule(JD, ThreadSafeModule(std::move(M), std::move(Ctx)));
206 }
207
208 Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) {
209 auto &JD = RT.getJITDylib();
210 if (auto &InitSym = MU.getInitializerSymbol())
211 InitSymbols[&JD].add(InitSym, SymbolLookupFlags::WeaklyReferencedSymbol);
212 else {
213 // If there's no identified init symbol attached, but there is a symbol
214 // with the GenericIRPlatform::InitFunctionPrefix, then treat that as
215 // an init function. Add the symbol to both the InitSymbols map (which
216 // will trigger a lookup to materialize the module) and the InitFunctions
217 // map (which holds the names of the symbols to execute).
218 for (auto &KV : MU.getSymbols())
219 if ((*KV.first).starts_with(InitFunctionPrefix)) {
220 InitSymbols[&JD].add(KV.first,
221 SymbolLookupFlags::WeaklyReferencedSymbol);
222 InitFunctions[&JD].add(KV.first);
223 } else if ((*KV.first).starts_with(DeInitFunctionPrefix)) {
224 DeInitFunctions[&JD].add(KV.first);
225 }
226 }
227 return Error::success();
228 }
229
230 Error initialize(JITDylib &JD) override {
231 LLVM_DEBUG({
232 dbgs() << "GenericLLVMIRPlatformSupport getting initializers to run\n";
233 });
234 if (auto Initializers = getInitializers(JD)) {
236 { dbgs() << "GenericLLVMIRPlatformSupport running initializers\n"; });
237 for (auto InitFnAddr : *Initializers) {
238 LLVM_DEBUG({
239 dbgs() << " Running init " << formatv("{0:x16}", InitFnAddr)
240 << "...\n";
241 });
242 auto *InitFn = InitFnAddr.toPtr<void (*)()>();
243 InitFn();
244 }
245 } else
246 return Initializers.takeError();
247 return Error::success();
248 }
249
250 Error deinitialize(JITDylib &JD) override {
251 LLVM_DEBUG({
252 dbgs() << "GenericLLVMIRPlatformSupport getting deinitializers to run\n";
253 });
254 if (auto Deinitializers = getDeinitializers(JD)) {
255 LLVM_DEBUG({
256 dbgs() << "GenericLLVMIRPlatformSupport running deinitializers\n";
257 });
258 for (auto DeinitFnAddr : *Deinitializers) {
259 LLVM_DEBUG({
260 dbgs() << " Running deinit " << formatv("{0:x16}", DeinitFnAddr)
261 << "...\n";
262 });
263 auto *DeinitFn = DeinitFnAddr.toPtr<void (*)()>();
264 DeinitFn();
265 }
266 } else
267 return Deinitializers.takeError();
268
269 return Error::success();
270 }
271
272 void registerInitFunc(JITDylib &JD, SymbolStringPtr InitName) {
274 [&]() { InitFunctions[&JD].add(InitName); });
275 }
276
277 void registerDeInitFunc(JITDylib &JD, SymbolStringPtr DeInitName) {
279 [&]() { DeInitFunctions[&JD].add(DeInitName); });
280 }
281
282private:
283 Expected<std::vector<ExecutorAddr>> getInitializers(JITDylib &JD) {
284 if (auto Err = issueInitLookups(JD))
285 return std::move(Err);
286
288 std::vector<JITDylibSP> DFSLinkOrder;
289
290 if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
291 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
292 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
293 else
294 return DFSLinkOrderOrErr.takeError();
295
296 for (auto &NextJD : DFSLinkOrder) {
297 auto IFItr = InitFunctions.find(NextJD.get());
298 if (IFItr != InitFunctions.end()) {
299 LookupSymbols[NextJD.get()] = std::move(IFItr->second);
300 InitFunctions.erase(IFItr);
301 }
302 }
303 return Error::success();
304 }))
305 return std::move(Err);
306
307 LLVM_DEBUG({
308 dbgs() << "JITDylib init order is [ ";
309 for (auto &JD : llvm::reverse(DFSLinkOrder))
310 dbgs() << "\"" << JD->getName() << "\" ";
311 dbgs() << "]\n";
312 dbgs() << "Looking up init functions:\n";
313 for (auto &KV : LookupSymbols)
314 dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
315 });
316
317 auto &ES = getExecutionSession();
318 auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
319
320 if (!LookupResult)
321 return LookupResult.takeError();
322
323 std::vector<ExecutorAddr> Initializers;
324 while (!DFSLinkOrder.empty()) {
325 auto &NextJD = *DFSLinkOrder.back();
326 DFSLinkOrder.pop_back();
327 auto InitsItr = LookupResult->find(&NextJD);
328 if (InitsItr == LookupResult->end())
329 continue;
330 for (auto &KV : InitsItr->second)
331 Initializers.push_back(KV.second.getAddress());
332 }
333
334 return Initializers;
335 }
336
337 Expected<std::vector<ExecutorAddr>> getDeinitializers(JITDylib &JD) {
338 auto &ES = getExecutionSession();
339
340 auto LLJITRunAtExits = J.mangleAndIntern("__lljit_run_atexits");
341
343 std::vector<JITDylibSP> DFSLinkOrder;
344
345 if (auto Err = ES.runSessionLocked([&]() -> Error {
346 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
347 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
348 else
349 return DFSLinkOrderOrErr.takeError();
350
351 for (auto &NextJD : DFSLinkOrder) {
352 auto &JDLookupSymbols = LookupSymbols[NextJD.get()];
353 auto DIFItr = DeInitFunctions.find(NextJD.get());
354 if (DIFItr != DeInitFunctions.end()) {
355 LookupSymbols[NextJD.get()] = std::move(DIFItr->second);
356 DeInitFunctions.erase(DIFItr);
357 }
358 JDLookupSymbols.add(LLJITRunAtExits,
359 SymbolLookupFlags::WeaklyReferencedSymbol);
360 }
361 return Error::success();
362 }))
363 return std::move(Err);
364
365 LLVM_DEBUG({
366 dbgs() << "JITDylib deinit order is [ ";
367 for (auto &JD : DFSLinkOrder)
368 dbgs() << "\"" << JD->getName() << "\" ";
369 dbgs() << "]\n";
370 dbgs() << "Looking up deinit functions:\n";
371 for (auto &KV : LookupSymbols)
372 dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
373 });
374
375 auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
376
377 if (!LookupResult)
378 return LookupResult.takeError();
379
380 std::vector<ExecutorAddr> DeInitializers;
381 for (auto &NextJD : DFSLinkOrder) {
382 auto DeInitsItr = LookupResult->find(NextJD.get());
383 assert(DeInitsItr != LookupResult->end() &&
384 "Every JD should have at least __lljit_run_atexits");
385
386 auto RunAtExitsItr = DeInitsItr->second.find(LLJITRunAtExits);
387 if (RunAtExitsItr != DeInitsItr->second.end())
388 DeInitializers.push_back(RunAtExitsItr->second.getAddress());
389
390 for (auto &KV : DeInitsItr->second)
391 if (KV.first != LLJITRunAtExits)
392 DeInitializers.push_back(KV.second.getAddress());
393 }
394
395 return DeInitializers;
396 }
397
398 /// Issue lookups for all init symbols required to initialize JD (and any
399 /// JITDylibs that it depends on).
400 Error issueInitLookups(JITDylib &JD) {
401 DenseMap<JITDylib *, SymbolLookupSet> RequiredInitSymbols;
402 std::vector<JITDylibSP> DFSLinkOrder;
403
404 if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
405 if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
406 DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
407 else
408 return DFSLinkOrderOrErr.takeError();
409
410 for (auto &NextJD : DFSLinkOrder) {
411 auto ISItr = InitSymbols.find(NextJD.get());
412 if (ISItr != InitSymbols.end()) {
413 RequiredInitSymbols[NextJD.get()] = std::move(ISItr->second);
414 InitSymbols.erase(ISItr);
415 }
416 }
417 return Error::success();
418 }))
419 return Err;
420
421 return Platform::lookupInitSymbols(getExecutionSession(),
422 RequiredInitSymbols)
423 .takeError();
424 }
425
426 static void registerCxaAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
427 void *DSOHandle) {
428 LLVM_DEBUG({
429 dbgs() << "Registering cxa atexit function " << (void *)F << " for JD "
430 << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
431 });
432 static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
433 F, Ctx, DSOHandle);
434 }
435
436 static void registerAtExitHelper(void *Self, void *DSOHandle, void (*F)()) {
437 LLVM_DEBUG({
438 dbgs() << "Registering atexit function " << (void *)F << " for JD "
439 << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
440 });
441 static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
442 reinterpret_cast<void (*)(void *)>(F), nullptr, DSOHandle);
443 }
444
445 static void runAtExitsHelper(void *Self, void *DSOHandle) {
446 LLVM_DEBUG({
447 dbgs() << "Running atexit functions for JD "
448 << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
449 });
450 static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.runAtExits(
451 DSOHandle);
452 }
453
454 // Constructs an LLVM IR module containing platform runtime globals,
455 // functions, and interposes.
456 ThreadSafeModule createPlatformRuntimeModule() {
457 auto Ctx = std::make_unique<LLVMContext>();
458 auto M = std::make_unique<Module>("__standard_lib", *Ctx);
459 M->setDataLayout(J.getDataLayout());
460
461 auto *GenericIRPlatformSupportTy =
462 StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
463
464 auto *PlatformInstanceDecl = new GlobalVariable(
465 *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
466 nullptr, "__lljit.platform_support_instance");
467
468 auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
469 auto *BytePtrTy = PointerType::getUnqual(*Ctx);
470 auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(*Ctx);
471
472 auto *CxaAtExit = addHelperAndWrapper(
473 *M, "__cxa_atexit",
474 FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
475 false),
476 GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
477 {PlatformInstanceDecl});
478 Attribute::AttrKind CxaAtExitExtAttr =
479 TargetLibraryInfo::getExtAttrForI32Return(J.getTargetTriple());
480 if (CxaAtExitExtAttr != Attribute::None)
481 CxaAtExit->addRetAttr(CxaAtExitExtAttr);
482
483 return ThreadSafeModule(std::move(M), std::move(Ctx));
484 }
485
486 LLJIT &J;
487 std::string InitFunctionPrefix;
488 std::string DeInitFunctionPrefix;
492 ItaniumCXAAtExitSupport AtExitMgr;
493};
494
495Error GenericLLVMIRPlatform::setupJITDylib(JITDylib &JD) {
496 return S.setupJITDylib(JD);
497}
498
499Error GenericLLVMIRPlatform::teardownJITDylib(JITDylib &JD) {
500 return Error::success();
501}
502
503Error GenericLLVMIRPlatform::notifyAdding(ResourceTracker &RT,
504 const MaterializationUnit &MU) {
505 return S.notifyAdding(RT, MU);
506}
507
509GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
511 auto Err = TSM.withModuleDo([&](Module &M) -> Error {
512 auto &Ctx = M.getContext();
513 auto *GlobalCtors = M.getNamedGlobal("llvm.global_ctors");
514 auto *GlobalDtors = M.getNamedGlobal("llvm.global_dtors");
515
516 auto RegisterCOrDtors = [&](GlobalVariable *GlobalCOrDtors,
517 bool isCtor) -> Error {
518 // If there's no llvm.global_c/dtor or it's just a decl then skip.
519 if (!GlobalCOrDtors || GlobalCOrDtors->isDeclaration())
520 return Error::success();
521 std::string InitOrDeInitFunctionName;
522 if (isCtor)
523 raw_string_ostream(InitOrDeInitFunctionName)
524 << InitFunctionPrefix << M.getModuleIdentifier();
525 else
526 raw_string_ostream(InitOrDeInitFunctionName)
527 << DeInitFunctionPrefix << M.getModuleIdentifier();
528
529 MangleAndInterner Mangle(PS.getExecutionSession(), M.getDataLayout());
530 auto InternedInitOrDeInitName = Mangle(InitOrDeInitFunctionName);
531 if (auto Err = R.defineMaterializing(
532 {{InternedInitOrDeInitName, JITSymbolFlags::Callable}}))
533 return Err;
534
535 auto *InitOrDeInitFunc = Function::Create(
536 FunctionType::get(Type::getVoidTy(Ctx), {}, false),
537 GlobalValue::ExternalLinkage, InitOrDeInitFunctionName, &M);
538 InitOrDeInitFunc->setVisibility(GlobalValue::HiddenVisibility);
539 std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
540 auto COrDtors = isCtor ? getConstructors(M) : getDestructors(M);
541
542 for (auto E : COrDtors)
543 InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
544 llvm::stable_sort(InitsOrDeInits, llvm::less_second());
545
546 auto *InitOrDeInitFuncEntryBlock =
547 BasicBlock::Create(Ctx, "entry", InitOrDeInitFunc);
548 IRBuilder<> IB(InitOrDeInitFuncEntryBlock);
549 for (auto &KV : InitsOrDeInits)
550 IB.CreateCall(KV.first);
551 IB.CreateRetVoid();
552
553 if (isCtor)
554 PS.registerInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
555 else
556 PS.registerDeInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
557
558 GlobalCOrDtors->eraseFromParent();
559 return Error::success();
560 };
561
562 if (auto Err = RegisterCOrDtors(GlobalCtors, true))
563 return Err;
564 if (auto Err = RegisterCOrDtors(GlobalDtors, false))
565 return Err;
566
567 return Error::success();
568 });
569
570 if (Err)
571 return std::move(Err);
572
573 return std::move(TSM);
574}
575
576/// Inactive Platform Support
577///
578/// Explicitly disables platform support. JITDylibs are not scanned for special
579/// init/deinit symbols. No runtime API interposes are injected.
580class InactivePlatformSupport : public LLJIT::PlatformSupport {
581public:
582 InactivePlatformSupport() = default;
583
584 Error initialize(JITDylib &JD) override {
585 LLVM_DEBUG(dbgs() << "InactivePlatformSupport: no initializers running for "
586 << JD.getName() << "\n");
587 return Error::success();
588 }
589
590 Error deinitialize(JITDylib &JD) override {
592 dbgs() << "InactivePlatformSupport: no deinitializers running for "
593 << JD.getName() << "\n");
594 return Error::success();
595 }
596};
597
598} // end anonymous namespace
599
600namespace llvm {
601namespace orc {
602
606 using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t);
607 using SPSDLUpdateSig = int32_t(SPSExecutorAddr);
608 enum dlopen_mode : int32_t {
609 ORC_RT_RTLD_LAZY = 0x1,
610 ORC_RT_RTLD_NOW = 0x2,
611 ORC_RT_RTLD_LOCAL = 0x4,
612 ORC_RT_RTLD_GLOBAL = 0x8
613 };
614
615 auto &ES = J.getExecutionSession();
616 auto MainSearchOrder = J.getMainJITDylib().withLinkOrderDo(
617 [](const JITDylibSearchOrder &SO) { return SO; });
618 StringRef WrapperToCall = "__orc_rt_jit_dlopen_wrapper";
619 bool dlupdate = false;
620 const Triple &TT = ES.getTargetTriple();
621 if (TT.isOSBinFormatMachO() || TT.isOSBinFormatELF()) {
622 if (InitializedDylib.contains(&JD)) {
623 WrapperToCall = "__orc_rt_jit_dlupdate_wrapper";
624 dlupdate = true;
625 } else
626 InitializedDylib.insert(&JD);
627 }
628
629 if (auto WrapperAddr =
630 ES.lookup(MainSearchOrder, J.mangleAndIntern(WrapperToCall))) {
631 if (dlupdate) {
632 int32_t result;
633 auto E = ES.callSPSWrapper<SPSDLUpdateSig>(WrapperAddr->getAddress(),
634 result, DSOHandles[&JD]);
635 if (E)
636 return E;
637 else if (result)
638 return make_error<StringError>("dlupdate failed",
640 } else
641 return ES.callSPSWrapper<SPSDLOpenSig>(WrapperAddr->getAddress(),
642 DSOHandles[&JD], JD.getName(),
643 int32_t(ORC_RT_RTLD_LAZY));
644 } else
645 return WrapperAddr.takeError();
646
647 return Error::success();
648}
649
652 using SPSDLCloseSig = int32_t(SPSExecutorAddr);
653
654 auto &ES = J.getExecutionSession();
655 auto MainSearchOrder = J.getMainJITDylib().withLinkOrderDo(
656 [](const JITDylibSearchOrder &SO) { return SO; });
657
658 if (auto WrapperAddr = ES.lookup(
659 MainSearchOrder, J.mangleAndIntern("__orc_rt_jit_dlclose_wrapper"))) {
660 int32_t result;
661 auto E = J.getExecutionSession().callSPSWrapper<SPSDLCloseSig>(
662 WrapperAddr->getAddress(), result, DSOHandles[&JD]);
663 if (E)
664 return E;
665 else if (result)
666 return make_error<StringError>("dlclose failed",
668 DSOHandles.erase(&JD);
669 InitializedDylib.erase(&JD);
670 } else
671 return WrapperAddr.takeError();
672 return Error::success();
673}
674
677 J.InitHelperTransformLayer->setTransform(std::move(T));
678}
679
681
683
684 LLVM_DEBUG(dbgs() << "Preparing to create LLJIT instance...\n");
685
686 if (!JTMB) {
687 LLVM_DEBUG({
688 dbgs() << " No explicitly set JITTargetMachineBuilder. "
689 "Detecting host...\n";
690 });
691 if (auto JTMBOrErr = JITTargetMachineBuilder::detectHost())
692 JTMB = std::move(*JTMBOrErr);
693 else
694 return JTMBOrErr.takeError();
695 }
696
697 if ((ES || EPC) && NumCompileThreads)
698 return make_error<StringError>(
699 "NumCompileThreads cannot be used with a custom ExecutionSession or "
700 "ExecutorProcessControl",
702
703#if !LLVM_ENABLE_THREADS
704 if (NumCompileThreads)
705 return make_error<StringError>(
706 "LLJIT num-compile-threads is " + Twine(NumCompileThreads) +
707 " but LLVM was compiled with LLVM_ENABLE_THREADS=Off",
709#endif // !LLVM_ENABLE_THREADS
710
711 // Only used in debug builds.
712 [[maybe_unused]] bool ConcurrentCompilationSettingDefaulted =
713 !SupportConcurrentCompilation;
714
715 if (!SupportConcurrentCompilation) {
716#if LLVM_ENABLE_THREADS
717 SupportConcurrentCompilation = NumCompileThreads || ES || EPC;
718#else
719 SupportConcurrentCompilation = false;
720#endif // LLVM_ENABLE_THREADS
721 } else {
722#if !LLVM_ENABLE_THREADS
723 if (*SupportConcurrentCompilation)
724 return make_error<StringError>(
725 "LLJIT concurrent compilation support requested, but LLVM was built "
726 "with LLVM_ENABLE_THREADS=Off",
728#endif // !LLVM_ENABLE_THREADS
729 }
730
731 LLVM_DEBUG({
732 dbgs() << " JITTargetMachineBuilder is "
733 << JITTargetMachineBuilderPrinter(*JTMB, " ")
734 << " Pre-constructed ExecutionSession: " << (ES ? "Yes" : "No")
735 << "\n"
736 << " DataLayout: ";
737 if (DL)
738 dbgs() << DL->getStringRepresentation() << "\n";
739 else
740 dbgs() << "None (will be created by JITTargetMachineBuilder)\n";
741
742 dbgs() << " Custom object-linking-layer creator: "
743 << (CreateObjectLinkingLayer ? "Yes" : "No") << "\n"
744 << " Custom compile-function creator: "
745 << (CreateCompileFunction ? "Yes" : "No") << "\n"
746 << " Custom platform-setup function: "
747 << (SetUpPlatform ? "Yes" : "No") << "\n"
748 << " Support concurrent compilation: "
749 << (*SupportConcurrentCompilation ? "Yes" : "No");
750 if (ConcurrentCompilationSettingDefaulted)
751 dbgs() << " (defaulted based on ES / EPC / NumCompileThreads)\n";
752 else
753 dbgs() << "\n";
754 dbgs() << " Number of compile threads: " << NumCompileThreads << "\n";
755 });
756
757 // Create DL if not specified.
758 if (!DL) {
759 if (auto DLOrErr = JTMB->getDefaultDataLayoutForTarget())
760 DL = std::move(*DLOrErr);
761 else
762 return DLOrErr.takeError();
763 }
764
765 // If neither ES nor EPC has been set then create an EPC instance.
766 if (!ES && !EPC) {
767 LLVM_DEBUG({
768 dbgs() << "ExecutorProcessControl not specified, "
769 "Creating SelfExecutorProcessControl instance\n";
770 });
771
772 std::unique_ptr<TaskDispatcher> D = nullptr;
773#if LLVM_ENABLE_THREADS
774 if (*SupportConcurrentCompilation) {
775 std::optional<size_t> NumThreads = std ::nullopt;
776 if (NumCompileThreads)
777 NumThreads = NumCompileThreads;
778 D = std::make_unique<DynamicThreadPoolTaskDispatcher>(NumThreads);
779 } else
780 D = std::make_unique<InPlaceTaskDispatcher>();
781#endif // LLVM_ENABLE_THREADS
782 if (auto EPCOrErr =
783 SelfExecutorProcessControl::Create(nullptr, std::move(D), nullptr))
784 EPC = std::move(*EPCOrErr);
785 else
786 return EPCOrErr.takeError();
787 } else if (EPC) {
788 LLVM_DEBUG({
789 dbgs() << "Using explicitly specified ExecutorProcessControl instance "
790 << EPC.get() << "\n";
791 });
792 } else {
793 LLVM_DEBUG({
794 dbgs() << "Using explicitly specified ExecutionSession instance "
795 << ES.get() << "\n";
796 });
797 }
798
799 // If the client didn't configure any linker options then auto-configure the
800 // JIT linker.
801 if (!CreateObjectLinkingLayer) {
802 auto &TT = JTMB->getTargetTriple();
803 bool UseJITLink = false;
804 switch (TT.getArch()) {
805 case Triple::riscv64:
807 UseJITLink = true;
808 break;
809 case Triple::aarch64:
810 UseJITLink = !TT.isOSBinFormatCOFF();
811 break;
812 case Triple::arm:
813 case Triple::armeb:
814 case Triple::thumb:
815 case Triple::thumbeb:
816 UseJITLink = TT.isOSBinFormatELF();
817 break;
818 case Triple::x86_64:
819 UseJITLink = !TT.isOSBinFormatCOFF();
820 break;
821 case Triple::ppc64:
822 UseJITLink = TT.isPPC64ELFv2ABI();
823 break;
824 case Triple::ppc64le:
825 UseJITLink = TT.isOSBinFormatELF();
826 break;
827 default:
828 break;
829 }
830 if (UseJITLink) {
831 if (!JTMB->getCodeModel())
832 JTMB->setCodeModel(CodeModel::Small);
833 JTMB->setRelocationModel(Reloc::PIC_);
834 CreateObjectLinkingLayer =
835 [](ExecutionSession &ES) -> Expected<std::unique_ptr<ObjectLayer>> {
836 return std::make_unique<ObjectLinkingLayer>(ES);
837 };
838 }
839 }
840
841 // If we need a process JITDylib but no setup function has been given then
842 // create a default one.
843 if (!SetupProcessSymbolsJITDylib && LinkProcessSymbolsByDefault) {
844 LLVM_DEBUG(dbgs() << "Creating default Process JD setup function\n");
845 SetupProcessSymbolsJITDylib = [](LLJIT &J) -> Expected<JITDylibSP> {
846 auto &JD =
847 J.getExecutionSession().createBareJITDylib("<Process Symbols>");
849 J.getExecutionSession());
850 if (!G)
851 return G.takeError();
852 JD.addGenerator(std::move(*G));
853 return &JD;
854 };
855 }
856
857 return Error::success();
858}
859
861 if (auto Err = ES->endSession())
862 ES->reportError(std::move(Err));
863}
864
866
868
870 auto JD = ES->createJITDylib(std::move(Name));
871 if (!JD)
872 return JD.takeError();
873
875 return JD;
876}
877
880 if (!G)
881 return G.takeError();
882
883 if (auto *ExistingJD = ES->getJITDylibByName(Path))
884 return *ExistingJD;
885
886 auto &JD = ES->createBareJITDylib(Path);
887 JD.addGenerator(std::move(*G));
888 return JD;
889}
890
892 std::unique_ptr<MemoryBuffer> LibBuffer) {
894 std::move(LibBuffer));
895 if (!G)
896 return G.takeError();
897
898 JD.addGenerator(std::move(*G));
899
900 return Error::success();
901}
902
905 if (!G)
906 return G.takeError();
907
908 JD.addGenerator(std::move(*G));
909
910 return Error::success();
911}
912
914 assert(TSM && "Can not add null module");
915
916 if (auto Err =
917 TSM.withModuleDo([&](Module &M) { return applyDataLayout(M); }))
918 return Err;
919
920 return InitHelperTransformLayer->add(std::move(RT), std::move(TSM));
921}
922
924 return addIRModule(JD.getDefaultResourceTracker(), std::move(TSM));
925}
926
928 std::unique_ptr<MemoryBuffer> Obj) {
929 assert(Obj && "Can not add null object");
930
931 return ObjTransformLayer->add(std::move(RT), std::move(Obj));
932}
933
934Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
935 return addObjectFile(JD.getDefaultResourceTracker(), std::move(Obj));
936}
937
940 if (auto Sym = ES->lookup(
942 Name))
943 return Sym->getAddress();
944 else
945 return Sym.takeError();
946}
947
950
951 // If the config state provided an ObjectLinkingLayer factory then use it.
954
955 // Otherwise default to creating an RTDyldObjectLinkingLayer that constructs
956 // a new SectionMemoryManager for each object.
957 auto GetMemMgr = [](const MemoryBuffer &) {
958 return std::make_unique<SectionMemoryManager>();
959 };
960 auto Layer =
961 std::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
962
963 if (S.JTMB->getTargetTriple().isOSBinFormatCOFF()) {
964 Layer->setOverrideObjectFlagsWithResponsibilityFlags(true);
965 Layer->setAutoClaimResponsibilityForObjectSymbols(true);
966 }
967
968 if (S.JTMB->getTargetTriple().isOSBinFormatELF() &&
969 (S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64 ||
970 S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64le))
971 Layer->setAutoClaimResponsibilityForObjectSymbols(true);
972
973 // FIXME: Explicit conversion to std::unique_ptr<ObjectLayer> added to silence
974 // errors from some GCC / libstdc++ bots. Remove this conversion (i.e.
975 // just return ObjLinkingLayer) once those bots are upgraded.
976 return std::unique_ptr<ObjectLayer>(std::move(Layer));
977}
978
982
983 /// If there is a custom compile function creator set then use it.
985 return S.CreateCompileFunction(std::move(JTMB));
986
987 // If using a custom EPC then use a ConcurrentIRCompiler by default.
989 return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
990
991 auto TM = JTMB.createTargetMachine();
992 if (!TM)
993 return TM.takeError();
994
995 return std::make_unique<TMOwningSimpleCompiler>(std::move(*TM));
996}
997
999 : DL(std::move(*S.DL)), TT(S.JTMB->getTargetTriple()) {
1000
1002
1003 assert(!(S.EPC && S.ES) && "EPC and ES should not both be set");
1004
1005 if (S.EPC) {
1006 ES = std::make_unique<ExecutionSession>(std::move(S.EPC));
1007 } else if (S.ES)
1008 ES = std::move(S.ES);
1009 else {
1010 if (auto EPC = SelfExecutorProcessControl::Create()) {
1011 ES = std::make_unique<ExecutionSession>(std::move(*EPC));
1012 } else {
1013 Err = EPC.takeError();
1014 return;
1015 }
1016 }
1017
1018 auto ObjLayer = createObjectLinkingLayer(S, *ES);
1019 if (!ObjLayer) {
1020 Err = ObjLayer.takeError();
1021 return;
1022 }
1023 ObjLinkingLayer = std::move(*ObjLayer);
1025 std::make_unique<ObjectTransformLayer>(*ES, *ObjLinkingLayer);
1026
1027 {
1028 auto CompileFunction = createCompileFunction(S, std::move(*S.JTMB));
1029 if (!CompileFunction) {
1030 Err = CompileFunction.takeError();
1031 return;
1032 }
1033 CompileLayer = std::make_unique<IRCompileLayer>(
1034 *ES, *ObjTransformLayer, std::move(*CompileFunction));
1035 TransformLayer = std::make_unique<IRTransformLayer>(*ES, *CompileLayer);
1037 std::make_unique<IRTransformLayer>(*ES, *TransformLayer);
1038 }
1039
1041 InitHelperTransformLayer->setCloneToNewContextOnEmit(true);
1042
1044 if (auto ProcSymsJD = S.SetupProcessSymbolsJITDylib(*this)) {
1045 ProcessSymbols = ProcSymsJD->get();
1046 } else {
1047 Err = ProcSymsJD.takeError();
1048 return;
1049 }
1050 }
1051
1052 if (S.PrePlatformSetup)
1053 if ((Err = S.PrePlatformSetup(*this)))
1054 return;
1055
1056 if (!S.SetUpPlatform)
1058
1059 if (auto PlatformJDOrErr = S.SetUpPlatform(*this)) {
1060 Platform = PlatformJDOrErr->get();
1061 if (Platform)
1062 DefaultLinks.push_back(
1064 } else {
1065 Err = PlatformJDOrErr.takeError();
1066 return;
1067 }
1068
1070 DefaultLinks.push_back(
1072
1073 if (auto MainOrErr = createJITDylib("main"))
1074 Main = &*MainOrErr;
1075 else {
1076 Err = MainOrErr.takeError();
1077 return;
1078 }
1079}
1080
1081std::string LLJIT::mangle(StringRef UnmangledName) const {
1082 std::string MangledName;
1083 {
1084 raw_string_ostream MangledNameStream(MangledName);
1085 Mangler::getNameWithPrefix(MangledNameStream, UnmangledName, DL);
1086 }
1087 return MangledName;
1088}
1089
1091 if (M.getDataLayout().isDefault())
1092 M.setDataLayout(DL);
1093
1094 if (M.getDataLayout() != DL)
1095 return make_error<StringError>(
1096 "Added modules have incompatible data layouts: " +
1097 M.getDataLayout().getStringRepresentation() + " (module) vs " +
1098 DL.getStringRepresentation() + " (jit)",
1100
1101 return Error::success();
1102}
1103
1105 LLVM_DEBUG({ dbgs() << "Setting up orc platform support for LLJIT\n"; });
1106 J.setPlatformSupport(std::make_unique<ORCPlatformSupport>(J));
1107 return Error::success();
1108}
1109
1111public:
1114 if (!DLLName.ends_with_insensitive(".dll"))
1115 return make_error<StringError>("DLLName not ending with .dll",
1117 auto DLLNameStr = DLLName.str(); // Guarantees null-termination.
1118 auto DLLJD = J.loadPlatformDynamicLibrary(DLLNameStr.c_str());
1119 if (!DLLJD)
1120 return DLLJD.takeError();
1121 JD.addToLinkOrder(*DLLJD);
1122 return Error::success();
1123 }
1124
1125private:
1126 LLJIT &J;
1127};
1128
1130 auto ProcessSymbolsJD = J.getProcessSymbolsJITDylib();
1131 if (!ProcessSymbolsJD)
1132 return make_error<StringError>(
1133 "Native platforms require a process symbols JITDylib",
1135
1136 const Triple &TT = J.getTargetTriple();
1137 ObjectLinkingLayer *ObjLinkingLayer =
1138 dyn_cast<ObjectLinkingLayer>(&J.getObjLinkingLayer());
1139
1140 if (!ObjLinkingLayer)
1141 return make_error<StringError>(
1142 "ExecutorNativePlatform requires ObjectLinkingLayer",
1144
1145 std::unique_ptr<MemoryBuffer> RuntimeArchiveBuffer;
1146 if (OrcRuntime.index() == 0) {
1147 auto A = errorOrToExpected(MemoryBuffer::getFile(std::get<0>(OrcRuntime)));
1148 if (!A)
1149 return A.takeError();
1150 RuntimeArchiveBuffer = std::move(*A);
1151 } else
1152 RuntimeArchiveBuffer = std::move(std::get<1>(OrcRuntime));
1153
1154 auto &ES = J.getExecutionSession();
1155 auto &PlatformJD = ES.createBareJITDylib("<Platform>");
1156 PlatformJD.addToLinkOrder(*ProcessSymbolsJD);
1157
1158 J.setPlatformSupport(std::make_unique<ORCPlatformSupport>(J));
1159
1160 switch (TT.getObjectFormat()) {
1161 case Triple::COFF: {
1162 const char *VCRuntimePath = nullptr;
1163 bool StaticVCRuntime = false;
1164 if (VCRuntime) {
1165 VCRuntimePath = VCRuntime->first.c_str();
1166 StaticVCRuntime = VCRuntime->second;
1167 }
1168 if (auto P = COFFPlatform::Create(
1169 *ObjLinkingLayer, PlatformJD, std::move(RuntimeArchiveBuffer),
1170 LoadAndLinkDynLibrary(J), StaticVCRuntime, VCRuntimePath))
1171 J.getExecutionSession().setPlatform(std::move(*P));
1172 else
1173 return P.takeError();
1174 break;
1175 }
1176 case Triple::ELF: {
1178 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1179 if (!G)
1180 return G.takeError();
1181
1182 if (auto P =
1183 ELFNixPlatform::Create(*ObjLinkingLayer, PlatformJD, std::move(*G)))
1184 J.getExecutionSession().setPlatform(std::move(*P));
1185 else
1186 return P.takeError();
1187 break;
1188 }
1189 case Triple::MachO: {
1191 *ObjLinkingLayer, std::move(RuntimeArchiveBuffer));
1192 if (!G)
1193 return G.takeError();
1194
1195 if (auto P =
1196 MachOPlatform::Create(*ObjLinkingLayer, PlatformJD, std::move(*G)))
1197 ES.setPlatform(std::move(*P));
1198 else
1199 return P.takeError();
1200 break;
1201 }
1202 default:
1203 return make_error<StringError>("Unsupported object format in triple " +
1204 TT.str(),
1206 }
1207
1208 return &PlatformJD;
1209}
1210
1212 LLVM_DEBUG(
1213 { dbgs() << "Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
1214 auto ProcessSymbolsJD = J.getProcessSymbolsJITDylib();
1215 if (!ProcessSymbolsJD)
1216 return make_error<StringError>(
1217 "Native platforms require a process symbols JITDylib",
1219
1220 auto &PlatformJD = J.getExecutionSession().createBareJITDylib("<Platform>");
1221 PlatformJD.addToLinkOrder(*ProcessSymbolsJD);
1222
1223 if (auto *OLL = dyn_cast<ObjectLinkingLayer>(&J.getObjLinkingLayer())) {
1224
1225 bool UseEHFrames = true;
1226
1227 // Enable compact-unwind support if possible.
1228 if (J.getTargetTriple().isOSDarwin() ||
1230
1231 // Check if the bootstrap map says that we should force eh-frames:
1232 // Older libunwinds require this as they don't have a dynamic
1233 // registration API for compact-unwind.
1234 std::optional<bool> ForceEHFrames;
1235 if (auto Err = J.getExecutionSession().getBootstrapMapValue<bool, bool>(
1236 "darwin-use-ehframes-only", ForceEHFrames))
1237 return Err;
1238 if (ForceEHFrames.has_value())
1239 UseEHFrames = *ForceEHFrames;
1240 else
1241 UseEHFrames = false;
1242
1243 // If UseEHFrames hasn't been set then we're good to use compact-unwind.
1244 if (!UseEHFrames) {
1245 if (auto UIRP =
1247 OLL->addPlugin(std::move(*UIRP));
1248 LLVM_DEBUG(dbgs() << "Enabled compact-unwind support.\n");
1249 } else
1250 return UIRP.takeError();
1251 }
1252 }
1253
1254 // Otherwise fall back to standard unwind registration.
1255 if (UseEHFrames) {
1256 auto &ES = J.getExecutionSession();
1257 if (auto EHFP = EHFrameRegistrationPlugin::Create(ES)) {
1258 OLL->addPlugin(std::move(*EHFP));
1259 LLVM_DEBUG(dbgs() << "Enabled eh-frame support.\n");
1260 } else
1261 return EHFP.takeError();
1262 }
1263 }
1264
1266 std::make_unique<GenericLLVMIRPlatformSupport>(J, PlatformJD));
1267
1268 return &PlatformJD;
1269}
1270
1272 LLVM_DEBUG(
1273 { dbgs() << "Explicitly deactivated platform support for LLJIT\n"; });
1274 J.setPlatformSupport(std::make_unique<InactivePlatformSupport>());
1275 return nullptr;
1276}
1277
1280 return Err;
1281 TT = JTMB->getTargetTriple();
1282 return Error::success();
1283}
1284
1286 assert(TSM && "Can not add null module");
1287
1288 if (auto Err = TSM.withModuleDo(
1289 [&](Module &M) -> Error { return applyDataLayout(M); }))
1290 return Err;
1291
1292 return CODLayer->add(JD, std::move(TSM));
1293}
1294
1295LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
1296
1297 // If LLJIT construction failed then bail out.
1298 if (Err)
1299 return;
1300
1301 ErrorAsOutParameter _(&Err);
1302
1303 /// Take/Create the lazy-compile callthrough manager.
1304 if (S.LCTMgr)
1305 LCTMgr = std::move(S.LCTMgr);
1306 else {
1307 if (auto LCTMgrOrErr = createLocalLazyCallThroughManager(
1309 LCTMgr = std::move(*LCTMgrOrErr);
1310 else {
1311 Err = LCTMgrOrErr.takeError();
1312 return;
1313 }
1314 }
1315
1316 // Take/Create the indirect stubs manager builder.
1317 auto ISMBuilder = std::move(S.ISMBuilder);
1318
1319 // If none was provided, try to build one.
1320 if (!ISMBuilder)
1322
1323 // No luck. Bail out.
1324 if (!ISMBuilder) {
1325 Err = make_error<StringError>("Could not construct "
1326 "IndirectStubsManagerBuilder for target " +
1327 S.TT.str(),
1329 return;
1330 }
1331
1332 // Create the IP Layer.
1333 IPLayer = std::make_unique<IRPartitionLayer>(*ES, *InitHelperTransformLayer);
1334
1335 // Create the COD layer.
1336 CODLayer = std::make_unique<CompileOnDemandLayer>(*ES, *IPLayer, *LCTMgr,
1337 std::move(ISMBuilder));
1338
1340 CODLayer->setCloneToNewContextOnEmit(true);
1341}
1342
1343// In-process LLJIT uses eh-frame section wrappers via EPC, so we need to force
1344// them to be linked in.
1348}
1349
1350} // End namespace orc.
1351} // End namespace llvm.
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
Definition: Compiler.h:236
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define _
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define G(x, y, z)
Definition: MD5.cpp:56
#define P(N)
if(PassOpts->AAPipeline)
static StringRef getName(Value *V)
LLVM_ABI llvm::orc::shared::CWrapperFunctionResult llvm_orc_deregisterEHFrameSectionAllocAction(const char *ArgData, size_t ArgSize)
LLVM_ABI llvm::orc::shared::CWrapperFunctionResult llvm_orc_registerEHFrameSectionAllocAction(const char *ArgData, size_t ArgSize)
#define LLVM_DEBUG(...)
Definition: Debug.h:119
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:88
@ None
No attributes have been set.
Definition: Attributes.h:90
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:206
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:206
Helper for Errors used as out-parameters.
Definition: Error.h:1144
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:166
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:316
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:67
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:68
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:69
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:53
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:507
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2780
Flags for symbols in the JIT.
Definition: JITSymbol.h:75
LLVM_ABI 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:121
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:52
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.
Definition: Module.h:67
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:720
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:233
LLVM_ABI bool ends_with_insensitive(StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.
Definition: StringRef.cpp:51
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:620
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
bool isPPC64ELFv2ABI() const
Tests whether the target 64-bit PowerPC big endian ABI is ELFv2.
Definition: Triple.h:1053
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:779
@ loongarch64
Definition: Triple.h:65
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:408
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:771
const std::string & str() const
Definition: Triple.h:475
bool isOSDarwin() const
Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, DriverKit, XROS, or bridgeOS).
Definition: Triple.h:608
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:766
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static Expected< std::unique_ptr< COFFPlatform > > Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, std::unique_ptr< MemoryBuffer > OrcRuntimeArchiveBuffer, LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime=false, const char *VCRuntimePath=nullptr, std::optional< SymbolAliasMap > RuntimeAliases=std::nullopt)
Try to create a COFFPlatform instance, adding the ORC runtime to the given JITDylib.
static Expected< std::unique_ptr< EHFrameRegistrationPlugin > > Create(ExecutionSession &ES)
static Expected< std::unique_ptr< ELFNixPlatform > > Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, std::unique_ptr< DefinitionGenerator > OrcRuntime, std::optional< SymbolAliasMap > RuntimeAliases=std::nullopt)
Try to create a ELFNixPlatform instance, adding the ORC runtime to the given JITDylib.
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 an EPCDynamicLibrarySearchGe...
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.
An ExecutionSession represents a running JIT program.
Definition: Core.h:1355
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
Definition: Core.h:1412
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition: Core.h:1652
LLVM_ABI JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
Definition: Core.cpp:1665
Error getBootstrapMapValue(StringRef Key, std::optional< T > &Val) const
Look up and SPS-deserialize a bootstrap map value.
Definition: Core.h:1577
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition: Core.h:1419
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
LLVM_ABI Expected< JITDylibSP > operator()(LLJIT &J)
Definition: LLJIT.cpp:1129
An interface for Itanium __cxa_atexit interposer implementations.
Represents a JIT'd dynamic library.
Definition: Core.h:902
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:1882
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Definition: Core.h:921
LLVM_ABI void addToLinkOrder(const JITDylibSearchOrder &NewLinks)
Append the given JITDylibSearchOrder to the link order for this JITDylib (discarding any elements alr...
Definition: Core.cpp:1019
static LLVM_ABI 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:1723
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
Definition: Core.h:1875
LLVM_ABI ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:671
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
Definition: Core.h:1865
A utility class for building TargetMachines for JITs.
static LLVM_ABI Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
LLVM_ABI Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
LLVM_ABI Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
Definition: LLJIT.cpp:682
ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib
Definition: LLJIT.h:321
ObjectLinkingLayerCreator CreateObjectLinkingLayer
Definition: LLJIT.h:322
std::unique_ptr< ExecutionSession > ES
Definition: LLJIT.h:317
unique_function< Error(LLJIT &)> PrePlatformSetup
Definition: LLJIT.h:324
CompileFunctionCreator CreateCompileFunction
Definition: LLJIT.h:323
std::optional< bool > SupportConcurrentCompilation
Definition: LLJIT.h:328
std::unique_ptr< ExecutorProcessControl > EPC
Definition: LLJIT.h:316
std::optional< JITTargetMachineBuilder > JTMB
Definition: LLJIT.h:318
PlatformSetupFunction SetUpPlatform
Definition: LLJIT.h:325
Initializer support for LLJIT.
Definition: LLJIT.h:49
virtual Error deinitialize(JITDylib &JD)=0
virtual Error initialize(JITDylib &JD)=0
static void setInitTransform(LLJIT &J, IRTransformLayer::TransformFunction T)
Definition: LLJIT.cpp:675
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
Definition: LLJIT.h:42
static Expected< std::unique_ptr< ObjectLayer > > createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES)
Definition: LLJIT.cpp:949
void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)
Set the PlatformSupport instance.
Definition: LLJIT.h:189
std::unique_ptr< ExecutionSession > ES
Definition: LLJIT.h:248
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
Definition: LLJIT.cpp:998
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Definition: LLJIT.cpp:927
Expected< JITDylib & > createJITDylib(std::string Name)
Create a new JITDylib with the given name and return a reference to it.
Definition: LLJIT.cpp:869
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
Definition: LLJIT.h:76
JITDylibSearchOrder DefaultLinks
Definition: LLJIT.h:255
const DataLayout & getDataLayout() const
Returns a reference to the DataLayout for this instance.
Definition: LLJIT.h:73
ObjectLayer & getObjLinkingLayer()
Returns a reference to the ObjLinkingLayer.
Definition: LLJIT.h:217
std::unique_ptr< ObjectTransformLayer > ObjTransformLayer
Definition: LLJIT.h:261
virtual ~LLJIT()
Destruct this instance.
Definition: LLJIT.cpp:860
std::string mangle(StringRef UnmangledName) const
Returns a linker-mangled version of UnmangledName.
Definition: LLJIT.cpp:1081
JITDylib * Main
Definition: LLJIT.h:253
JITDylibSP getPlatformJITDylib()
Returns the Platform JITDylib, which will contain the ORC runtime (if given) and any platform symbols...
Definition: LLJIT.cpp:867
Expected< JITDylib & > loadPlatformDynamicLibrary(const char *Path)
Load a (real) dynamic library and make its symbols available through a new JITDylib with the same nam...
Definition: LLJIT.cpp:878
std::unique_ptr< IRTransformLayer > InitHelperTransformLayer
Definition: LLJIT.h:264
std::unique_ptr< IRCompileLayer > CompileLayer
Definition: LLJIT.h:262
const Triple & getTargetTriple() const
Returns a reference to the triple for this instance.
Definition: LLJIT.h:70
JITDylibSP getProcessSymbolsJITDylib()
Returns the ProcessSymbols JITDylib, which by default reflects non-JIT'd symbols in the host process.
Definition: LLJIT.cpp:865
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:938
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
Definition: LLJIT.cpp:980
JITDylib * ProcessSymbols
Definition: LLJIT.h:251
JITDylib * Platform
Definition: LLJIT.h:252
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition: LLJIT.h:67
std::unique_ptr< IRTransformLayer > TransformLayer
Definition: LLJIT.h:263
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Definition: LLJIT.h:232
DataLayout DL
Definition: LLJIT.h:257
Error linkStaticLibraryInto(JITDylib &JD, std::unique_ptr< MemoryBuffer > LibBuffer)
Link a static library into the given JITDylib.
Definition: LLJIT.cpp:891
Error applyDataLayout(Module &M)
Definition: LLJIT.cpp:1090
std::unique_ptr< ObjectLayer > ObjLinkingLayer
Definition: LLJIT.h:260
LLVM_ABI friend Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition: LLJIT.cpp:1211
Triple TT
Definition: LLJIT.h:258
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
Definition: LLJIT.cpp:913
ExecutorAddr LazyCompileFailureAddr
Definition: LLJIT.h:523
std::unique_ptr< LazyCallThroughManager > LCTMgr
Definition: LLJIT.h:524
LLVM_ABI Error prepareForConstruction()
Definition: LLJIT.cpp:1278
IndirectStubsManagerBuilderFunction ISMBuilder
Definition: LLJIT.h:525
LLVM_ABI Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
Definition: LLJIT.cpp:1285
Error operator()(JITDylib &JD, StringRef DLLName)
Definition: LLJIT.cpp:1113
static Expected< std::unique_ptr< MachOPlatform > > Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, std::unique_ptr< DefinitionGenerator > OrcRuntime, HeaderOptions PlatformJDOpts={}, MachOHeaderMUBuilder BuildMachOHeaderMU=buildSimpleMachOHeaderMU, std::optional< SymbolAliasMap > RuntimeAliases=std::nullopt)
Try to create a MachOPlatform instance, adding the ORC runtime to the given JITDylib.
Mangles symbol names then uniques them in the context of an ExecutionSession.
Definition: Mangling.h:27
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:576
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).
Error deinitialize(orc::JITDylib &JD) override
Definition: LLJIT.cpp:650
Error initialize(orc::JITDylib &JD) override
Definition: LLJIT.cpp:603
An ObjectLayer implementation built on JITLink.
Platforms set up standard symbols and mediate interactions between dynamic initializers (e....
Definition: Core.h:1282
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:1492
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:78
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:93
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.
static Expected< std::shared_ptr< UnwindInfoRegistrationPlugin > > Create(ExecutionSession &ES, ExecutorAddr Register, ExecutorAddr Deregister)
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
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:178
LLVM_ABI 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.
Definition: Core.h:174
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
LLVM_ABI iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
LLVM_ABI Expected< JITDylibSP > setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
Definition: LLJIT.cpp:1271
LLVM_ATTRIBUTE_USED void linkComponents()
Definition: LLJIT.cpp:1345
LLVM_ABI std::function< std::unique_ptr< IndirectStubsManager >()> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indirect stubs manager builder.
LLVM_ABI Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, ExecutorAddr ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session.
LLVM_ABI Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition: LLJIT.cpp:1211
LLVM_ABI Error setUpOrcPlatformManually(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
Definition: LLJIT.cpp:1104
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void stable_sort(R &&Range)
Definition: STLExtras.h:2077
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2155
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:428
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
LLVM_ABI 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:769
Expected< T > errorOrToExpected(ErrorOr< T > &&EO)
Convert an ErrorOr<T> to an Expected<T>.
Definition: Error.h:1245
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Function object to check whether the second component of a container supported by std::get (like std:...
Definition: STLExtras.h:1481