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