LLVM 24.0.0git
MCJIT.cpp
Go to the documentation of this file.
1//===-- MCJIT.cpp - MC-based Just-in-Time Compiler ------------------------===//
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
9#include "MCJIT.h"
10#include "llvm/ADT/STLExtras.h"
16#include "llvm/IR/DataLayout.h"
18#include "llvm/IR/Function.h"
20#include "llvm/IR/Mangler.h"
21#include "llvm/IR/Module.h"
22#include "llvm/Object/Archive.h"
28#include <mutex>
29
30using namespace llvm;
31
32namespace {
33
34static struct RegisterJIT {
35 RegisterJIT() { MCJIT::Register(); }
36} JITRegistrator;
37
38}
39
40extern "C" void LLVMLinkInMCJIT() {
41}
42
44MCJIT::createJIT(std::unique_ptr<Module> M, std::string *ErrorStr,
45 std::shared_ptr<MCJITMemoryManager> MemMgr,
46 std::shared_ptr<LegacyJITSymbolResolver> Resolver,
47 std::unique_ptr<TargetMachine> TM) {
48 // Try to register the program as a source of symbols to resolve against.
49 //
50 // FIXME: Don't do this here.
52
53 if (!MemMgr || !Resolver) {
54 auto RTDyldMM = std::make_shared<SectionMemoryManager>();
55 if (!MemMgr)
56 MemMgr = RTDyldMM;
57 if (!Resolver)
58 Resolver = RTDyldMM;
59 }
60
61 return new MCJIT(std::move(M), std::move(TM), std::move(MemMgr),
62 std::move(Resolver));
63}
64
65MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> TM,
66 std::shared_ptr<MCJITMemoryManager> MemMgr,
67 std::shared_ptr<LegacyJITSymbolResolver> Resolver)
68 : ExecutionEngine(DataLayout(TM->getTargetTriple().computeDataLayout(
69 TM->Options.MCOptions.getABIName())),
70 std::move(M)),
71 TM(std::move(TM)), Ctx(nullptr), MemMgr(std::move(MemMgr)),
72 Resolver(*this, std::move(Resolver)), Dyld(*this->MemMgr, this->Resolver),
73 ObjCache(nullptr) {
74 // FIXME: We are managing our modules, so we do not want the base class
75 // ExecutionEngine to manage them as well. To avoid double destruction
76 // of the first (and only) module added in ExecutionEngine constructor
77 // we remove it from EE and will destruct it ourselves.
78 //
79 // It may make sense to move our module manager (based on SmallStPtr) back
80 // into EE if the JIT and Interpreter can live with it.
81 // If so, additional functions: addModule, removeModule, FindFunctionNamed,
82 // runStaticConstructorsDestructors could be moved back to EE as well.
83 //
84 std::unique_ptr<Module> First = std::move(Modules[0]);
85 Modules.clear();
86
87 if (First->getDataLayout().isDefault())
88 First->setDataLayout(getDataLayout());
89 if (First->getTargetTriple().empty())
90 First->setTargetTriple(this->TM->getTargetTriple());
91
92 OwnedModules.addModule(std::move(First));
94}
95
97 std::lock_guard<sys::Mutex> locked(lock);
98
99 Dyld.deregisterEHFrames();
100
101 for (auto &Obj : LoadedObjects)
102 if (Obj)
104
105 Archives.clear();
106}
107
108void MCJIT::addModule(std::unique_ptr<Module> M) {
109 std::lock_guard<sys::Mutex> locked(lock);
110
111 if (M->getDataLayout().isDefault())
112 M->setDataLayout(getDataLayout());
113 if (M->getTargetTriple().empty())
114 M->setTargetTriple(TM->getTargetTriple());
115
116 OwnedModules.addModule(std::move(M));
117}
118
120 std::lock_guard<sys::Mutex> locked(lock);
121 return OwnedModules.removeModule(M);
122}
123
124void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) {
125 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L = Dyld.loadObject(*Obj);
126 if (Dyld.hasError())
127 report_fatal_error(Dyld.getErrorString());
128
129 notifyObjectLoaded(*Obj, *L);
130
131 LoadedObjects.push_back(std::move(Obj));
132}
133
135 std::unique_ptr<object::ObjectFile> ObjFile;
136 std::unique_ptr<MemoryBuffer> MemBuf;
137 std::tie(ObjFile, MemBuf) = Obj.takeBinary();
138 addObjectFile(std::move(ObjFile));
139 Buffers.push_back(std::move(MemBuf));
140}
141
143 Archives.push_back(std::move(A));
144}
145
147 std::lock_guard<sys::Mutex> locked(lock);
148 ObjCache = NewCache;
149}
150
151std::unique_ptr<MemoryBuffer> MCJIT::emitObject(Module *M) {
152 assert(M && "Can not emit a null module");
153
154 std::lock_guard<sys::Mutex> locked(lock);
155
156 // Materialize all globals in the module if they have not been
157 // materialized already.
158 cantFail(M->materializeAll());
159
160 // This must be a module which has already been added but not loaded to this
161 // MCJIT instance, since these conditions are tested by our caller,
162 // generateCodeForModule.
163
165
166 // The RuntimeDyld will take ownership of this shortly
167 SmallVector<char, 4096> ObjBufferSV;
168 raw_svector_ostream ObjStream(ObjBufferSV);
169
170 // Turn the machine code intermediate representation into bytes in memory
171 // that may be executed.
172 if (TM->addPassesToEmitMC(PM, Ctx, ObjStream, !getVerifyModules()))
173 report_fatal_error("Target does not support MC emission!");
174
175 // Initialize passes.
176 PM.run(*M);
177 // Flush the output buffer to get the generated code into memory
178
179 auto CompiledObjBuffer = std::make_unique<SmallVectorMemoryBuffer>(
180 std::move(ObjBufferSV), /*RequiresNullTerminator=*/false);
181
182 // If we have an object cache, tell it about the new object.
183 // Note that we're using the compiled image, not the loaded image (as below).
184 if (ObjCache) {
185 // MemoryBuffer is a thin wrapper around the actual memory, so it's OK
186 // to create a temporary object here and delete it after the call.
187 MemoryBufferRef MB = CompiledObjBuffer->getMemBufferRef();
188 ObjCache->notifyObjectCompiled(M, MB);
189 }
190
191 return CompiledObjBuffer;
192}
193
195 // Get a thread lock to make sure we aren't trying to load multiple times
196 std::lock_guard<sys::Mutex> locked(lock);
197
198 // This must be a module which has already been added to this MCJIT instance.
199 assert(OwnedModules.ownsModule(M) &&
200 "MCJIT::generateCodeForModule: Unknown module.");
201
202 // Re-compilation is not supported
203 if (OwnedModules.hasModuleBeenLoaded(M))
204 return;
205
206 std::unique_ptr<MemoryBuffer> ObjectToLoad;
207 // Try to load the pre-compiled object from cache if possible
208 if (ObjCache)
209 ObjectToLoad = ObjCache->getObject(M);
210
211 assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
212
213 // If the cache did not contain a suitable object, compile the object
214 if (!ObjectToLoad) {
215 ObjectToLoad = emitObject(M);
216 assert(ObjectToLoad && "Compilation did not produce an object.");
217 }
218
219 // Load the object into the dynamic linker.
220 // MCJIT now owns the ObjectImage pointer (via its LoadedObjects list).
222 object::ObjectFile::createObjectFile(ObjectToLoad->getMemBufferRef());
223 if (!LoadedObject) {
224 std::string Buf;
225 raw_string_ostream OS(Buf);
226 logAllUnhandledErrors(LoadedObject.takeError(), OS);
228 }
229 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L =
230 Dyld.loadObject(*LoadedObject.get());
231
232 if (Dyld.hasError())
233 report_fatal_error(Dyld.getErrorString());
234
235 notifyObjectLoaded(*LoadedObject.get(), *L);
236
237 Buffers.push_back(std::move(ObjectToLoad));
238 LoadedObjects.push_back(std::move(*LoadedObject));
239
240 OwnedModules.markModuleAsLoaded(M);
241}
242
244 std::lock_guard<sys::Mutex> locked(lock);
245
246 // Resolve any outstanding relocations.
247 Dyld.resolveRelocations();
248
249 // Check for Dyld error.
250 if (Dyld.hasError())
251 ErrMsg = Dyld.getErrorString().str();
252
253 OwnedModules.markAllLoadedModulesAsFinalized();
254
255 // Register EH frame data for any module we own which has been loaded
256 Dyld.registerEHFrames();
257
258 // Set page permissions.
259 MemMgr->finalizeMemory();
260}
261
262// FIXME: Rename this.
264 std::lock_guard<sys::Mutex> locked(lock);
265
266 // Generate code for module is going to move objects out of the 'added' list,
267 // so we need to copy that out before using it:
268 SmallVector<Module *, 16> ModsToAdd(OwnedModules.added());
269
270 for (auto *M : ModsToAdd)
272
274}
275
277 std::lock_guard<sys::Mutex> locked(lock);
278
279 // This must be a module which has already been added to this MCJIT instance.
280 assert(OwnedModules.ownsModule(M) && "MCJIT::finalizeModule: Unknown module.");
281
282 // If the module hasn't been compiled, just do that.
283 if (!OwnedModules.hasModuleBeenLoaded(M))
285
287}
288
289JITSymbol MCJIT::findExistingSymbol(const std::string &Name) {
290 if (void *Addr = getPointerToGlobalIfAvailable(Name))
291 return JITSymbol(static_cast<uint64_t>(
292 reinterpret_cast<uintptr_t>(Addr)),
294
295 return Dyld.getSymbol(Name);
296}
297
298Module *MCJIT::findModuleForSymbol(const std::string &Name,
299 bool CheckFunctionsOnly) {
300 StringRef DemangledName = Name;
301 if (DemangledName[0] == getDataLayout().getGlobalPrefix())
302 DemangledName = DemangledName.substr(1);
303
304 std::lock_guard<sys::Mutex> locked(lock);
305
306 // If it hasn't already been generated, see if it's in one of our modules.
307 for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
308 E = OwnedModules.end_added();
309 I != E; ++I) {
310 Module *M = *I;
311 Function *F = M->getFunction(DemangledName);
312 if (F && !F->isDeclaration())
313 return M;
314 if (!CheckFunctionsOnly) {
315 GlobalVariable *G = M->getGlobalVariable(DemangledName);
316 if (G && !G->isDeclaration())
317 return M;
318 // FIXME: Do we need to worry about global aliases?
319 }
320 }
321 // We didn't find the symbol in any of our modules.
322 return nullptr;
323}
324
325uint64_t MCJIT::getSymbolAddress(const std::string &Name,
326 bool CheckFunctionsOnly) {
327 std::string MangledName;
328 {
329 raw_string_ostream MangledNameStream(MangledName);
330 Mangler::getNameWithPrefix(MangledNameStream, Name, getDataLayout());
331 }
332 if (auto Sym = findSymbol(MangledName, CheckFunctionsOnly)) {
333 if (auto AddrOrErr = Sym.getAddress())
334 return *AddrOrErr;
335 else
336 report_fatal_error(AddrOrErr.takeError());
337 } else if (auto Err = Sym.takeError())
338 report_fatal_error(Sym.takeError());
339 return 0;
340}
341
342JITSymbol MCJIT::findSymbol(const std::string &Name,
343 bool CheckFunctionsOnly) {
344 std::lock_guard<sys::Mutex> locked(lock);
345
346 // First, check to see if we already have this symbol.
347 if (auto Sym = findExistingSymbol(Name))
348 return Sym;
349
350 for (object::OwningBinary<object::Archive> &OB : Archives) {
351 object::Archive *A = OB.getBinary();
352 // Look for our symbols in each Archive
353 auto OptionalChildOrErr = A->findSym(Name);
354 if (!OptionalChildOrErr)
355 report_fatal_error(OptionalChildOrErr.takeError());
356 auto &OptionalChild = *OptionalChildOrErr;
357 if (OptionalChild) {
358 // FIXME: Support nested archives?
360 OptionalChild->getAsBinary();
361 if (!ChildBinOrErr) {
362 // TODO: Actually report errors helpfully.
363 consumeError(ChildBinOrErr.takeError());
364 continue;
365 }
366 std::unique_ptr<object::Binary> &ChildBin = ChildBinOrErr.get();
367 if (ChildBin->isObject()) {
368 std::unique_ptr<object::ObjectFile> OF(
369 static_cast<object::ObjectFile *>(ChildBin.release()));
370 // This causes the object file to be loaded.
371 addObjectFile(std::move(OF));
372 // The address should be here now.
373 if (auto Sym = findExistingSymbol(Name))
374 return Sym;
375 }
376 }
377 }
378
379 // If it hasn't already been generated, see if it's in one of our modules.
380 Module *M = findModuleForSymbol(Name, CheckFunctionsOnly);
381 if (M) {
383
384 // Check the RuntimeDyld table again, it should be there now.
385 return findExistingSymbol(Name);
386 }
387
388 // If a LazyFunctionCreator is installed, use it to get/create the function.
389 // FIXME: Should we instead have a LazySymbolCreator callback?
391 auto Addr = static_cast<uint64_t>(
392 reinterpret_cast<uintptr_t>(LazyFunctionCreator(Name)));
394 }
395
396 return nullptr;
397}
398
399uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
400 std::lock_guard<sys::Mutex> locked(lock);
401 uint64_t Result = getSymbolAddress(Name, false);
402 if (Result != 0)
404 return Result;
405}
406
407uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
408 std::lock_guard<sys::Mutex> locked(lock);
409 uint64_t Result = getSymbolAddress(Name, true);
410 if (Result != 0)
412 return Result;
413}
414
415// Deprecated. Use getFunctionAddress instead.
417 std::lock_guard<sys::Mutex> locked(lock);
418
419 Mangler Mang;
420 SmallString<128> Name;
421 TM->getNameWithPrefix(Name, F, Mang);
422
423 if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
424 bool AbortOnFailure = !F->hasExternalWeakLinkage();
425 void *Addr = getPointerToNamedFunction(Name, AbortOnFailure);
426 updateGlobalMapping(F, Addr);
427 return Addr;
428 }
429
430 Module *M = F->getParent();
431 bool HasBeenAddedButNotLoaded = OwnedModules.hasModuleBeenAddedButNotLoaded(M);
432
433 // Make sure the relevant module has been compiled and loaded.
434 if (HasBeenAddedButNotLoaded)
436 else if (!OwnedModules.hasModuleBeenLoaded(M)) {
437 // If this function doesn't belong to one of our modules, we're done.
438 // FIXME: Asking for the pointer to a function that hasn't been registered,
439 // and isn't a declaration (which is handled above) should probably
440 // be an assertion.
441 return nullptr;
442 }
443
444 // FIXME: Should the Dyld be retaining module information? Probably not.
445 //
446 // This is the accessor for the target address, so make sure to check the
447 // load address of the symbol, not the local address.
448 return (void*)Dyld.getSymbol(Name).getAddress();
449}
450
451void MCJIT::runStaticConstructorsDestructorsInModulePtrSet(
452 bool isDtors, ModulePtrSet::iterator I, ModulePtrSet::iterator E) {
453 for (; I != E; ++I) {
455 }
456}
457
459 // Execute global ctors/dtors for each module in the program.
460 runStaticConstructorsDestructorsInModulePtrSet(
461 isDtors, OwnedModules.begin_added(), OwnedModules.end_added());
462 runStaticConstructorsDestructorsInModulePtrSet(
463 isDtors, OwnedModules.begin_loaded(), OwnedModules.end_loaded());
464 runStaticConstructorsDestructorsInModulePtrSet(
465 isDtors, OwnedModules.begin_finalized(), OwnedModules.end_finalized());
466}
467
468Function *MCJIT::FindFunctionNamedInModulePtrSet(StringRef FnName,
469 ModulePtrSet::iterator I,
470 ModulePtrSet::iterator E) {
471 for (; I != E; ++I) {
472 Function *F = (*I)->getFunction(FnName);
473 if (F && !F->isDeclaration())
474 return F;
475 }
476 return nullptr;
477}
478
479GlobalVariable *MCJIT::FindGlobalVariableNamedInModulePtrSet(StringRef Name,
480 bool AllowInternal,
481 ModulePtrSet::iterator I,
482 ModulePtrSet::iterator E) {
483 for (; I != E; ++I) {
484 GlobalVariable *GV = (*I)->getGlobalVariable(Name, AllowInternal);
485 if (GV && !GV->isDeclaration())
486 return GV;
487 }
488 return nullptr;
489}
490
491
493 Function *F = FindFunctionNamedInModulePtrSet(
494 FnName, OwnedModules.begin_added(), OwnedModules.end_added());
495 if (!F)
496 F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_loaded(),
497 OwnedModules.end_loaded());
498 if (!F)
499 F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_finalized(),
500 OwnedModules.end_finalized());
501 return F;
502}
503
505 GlobalVariable *GV = FindGlobalVariableNamedInModulePtrSet(
506 Name, AllowInternal, OwnedModules.begin_added(), OwnedModules.end_added());
507 if (!GV)
508 GV = FindGlobalVariableNamedInModulePtrSet(Name, AllowInternal, OwnedModules.begin_loaded(),
509 OwnedModules.end_loaded());
510 if (!GV)
511 GV = FindGlobalVariableNamedInModulePtrSet(Name, AllowInternal, OwnedModules.begin_finalized(),
512 OwnedModules.end_finalized());
513 return GV;
514}
515
517 assert(F && "Function *F was null at entry to run()");
518
519 void *FPtr = getPointerToFunction(F);
520 finalizeModule(F->getParent());
521 assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
522 FunctionType *FTy = F->getFunctionType();
523 Type *RetTy = FTy->getReturnType();
524
525 assert((FTy->getNumParams() == ArgValues.size() ||
526 (FTy->isVarArg() && FTy->getNumParams() <= ArgValues.size())) &&
527 "Wrong number of arguments passed into function!");
528 assert(FTy->getNumParams() == ArgValues.size() &&
529 "This doesn't support passing arguments through varargs (yet)!");
530
531 // Handle some common cases first. These cases correspond to common `main'
532 // prototypes.
533 if (RetTy->isIntegerTy(32) || RetTy->isVoidTy()) {
534 switch (ArgValues.size()) {
535 case 3:
536 if (FTy->getParamType(0)->isIntegerTy(32) &&
537 FTy->getParamType(1)->isPointerTy() &&
538 FTy->getParamType(2)->isPointerTy()) {
539 int (*PF)(int, char **, const char **) =
540 (int(*)(int, char **, const char **))(intptr_t)FPtr;
541
542 // Call the function.
543 GenericValue rv;
544 rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
545 (char **)GVTOP(ArgValues[1]),
546 (const char **)GVTOP(ArgValues[2])));
547 return rv;
548 }
549 break;
550 case 2:
551 if (FTy->getParamType(0)->isIntegerTy(32) &&
552 FTy->getParamType(1)->isPointerTy()) {
553 int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr;
554
555 // Call the function.
556 GenericValue rv;
557 rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
558 (char **)GVTOP(ArgValues[1])));
559 return rv;
560 }
561 break;
562 case 1:
563 if (FTy->getNumParams() == 1 &&
564 FTy->getParamType(0)->isIntegerTy(32)) {
565 GenericValue rv;
566 int (*PF)(int) = (int(*)(int))(intptr_t)FPtr;
567 rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue()));
568 return rv;
569 }
570 break;
571 }
572 }
573
574 // Handle cases where no arguments are passed first.
575 if (ArgValues.empty()) {
576 GenericValue rv;
577 switch (RetTy->getTypeID()) {
578 default: llvm_unreachable("Unknown return type for function call!");
579 case Type::IntegerTyID: {
580 unsigned BitWidth = cast<IntegerType>(RetTy)->getBitWidth();
581 if (BitWidth == 1)
582 rv.IntVal = APInt(BitWidth, ((bool(*)())(intptr_t)FPtr)());
583 else if (BitWidth <= 8)
584 rv.IntVal = APInt(BitWidth, ((char(*)())(intptr_t)FPtr)());
585 else if (BitWidth <= 16)
586 rv.IntVal = APInt(BitWidth, ((short(*)())(intptr_t)FPtr)());
587 else if (BitWidth <= 32)
588 rv.IntVal = APInt(BitWidth, ((int(*)())(intptr_t)FPtr)());
589 else if (BitWidth <= 64)
590 rv.IntVal = APInt(BitWidth, ((int64_t(*)())(intptr_t)FPtr)());
591 else
592 llvm_unreachable("Integer types > 64 bits not supported");
593 return rv;
594 }
595 case Type::VoidTyID:
596 rv.IntVal = APInt(32, ((int (*)())(intptr_t)FPtr)(), true);
597 return rv;
598 case Type::FloatTyID:
599 rv.FloatVal = ((float(*)())(intptr_t)FPtr)();
600 return rv;
601 case Type::DoubleTyID:
602 rv.DoubleVal = ((double(*)())(intptr_t)FPtr)();
603 return rv;
605 case Type::FP128TyID:
607 llvm_unreachable("long double not supported yet");
609 return PTOGV(((void*(*)())(intptr_t)FPtr)());
610 }
611 }
612
613 report_fatal_error("MCJIT::runFunction does not support full-featured "
614 "argument passing. Please use "
615 "ExecutionEngine::getFunctionAddress and cast the result "
616 "to the desired function pointer type.");
617}
618
619void *MCJIT::getPointerToNamedFunction(StringRef Name, bool AbortOnFailure) {
621 if (auto Sym = Resolver.findSymbol(std::string(Name))) {
622 if (auto AddrOrErr = Sym.getAddress())
623 return reinterpret_cast<void*>(
624 static_cast<uintptr_t>(*AddrOrErr));
625 } else if (auto Err = Sym.takeError())
626 report_fatal_error(std::move(Err));
627 }
628
629 /// If a LazyFunctionCreator is installed, use it to get/create the function.
631 if (void *RP = LazyFunctionCreator(std::string(Name)))
632 return RP;
633
634 if (AbortOnFailure) {
635 report_fatal_error("Program used external function '"+Name+
636 "' which could not be resolved!");
637 }
638 return nullptr;
639}
640
642 if (!L)
643 return;
644 std::lock_guard<sys::Mutex> locked(lock);
645 EventListeners.push_back(L);
646}
647
649 if (!L)
650 return;
651 std::lock_guard<sys::Mutex> locked(lock);
652 auto I = find(reverse(EventListeners), L);
653 if (I != EventListeners.rend()) {
654 std::swap(*I, EventListeners.back());
655 EventListeners.pop_back();
656 }
657}
658
661 uint64_t Key =
662 static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Obj.getData().data()));
663 std::lock_guard<sys::Mutex> locked(lock);
664 MemMgr->notifyObjectLoaded(this, Obj);
665 for (JITEventListener *EL : EventListeners)
666 EL->notifyObjectLoaded(Key, Obj, L);
667}
668
670 uint64_t Key =
671 static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Obj.getData().data()));
672 std::lock_guard<sys::Mutex> locked(lock);
673 for (JITEventListener *L : EventListeners)
674 L->notifyFreeingObject(Key);
675}
676
678LinkingSymbolResolver::findSymbol(const std::string &Name) {
679 auto Result = ParentEngine.findSymbol(Name, false);
680 if (Result)
681 return Result;
682 if (ParentEngine.isSymbolSearchingDisabled())
683 return nullptr;
684 return ClientResolver->findSymbol(Name);
685}
686
687void LinkingSymbolResolver::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Module.h This file contains the declarations for the Module class.
static LVOptions Options
Definition LVOptions.cpp:25
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
This file contains some templates that are useful if you are working with the STL at all.
static Split data
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
const DataLayout & getDataLayout() const
bool getVerifyModules() const
void * getPointerToGlobalIfAvailable(StringRef S)
getPointerToGlobalIfAvailable - This returns the address of the specified global value if it is has a...
sys::Mutex lock
lock - This lock protects the ExecutionEngine and MCJIT classes.
virtual void runStaticConstructorsDestructors(bool isDtors)
runStaticConstructorsDestructors - This method is used to execute all of the static constructors or d...
FunctionCreator LazyFunctionCreator
LazyFunctionCreator - If an unknown function is needed, this function pointer is invoked to create it...
SmallVector< std::unique_ptr< Module >, 1 > Modules
The list of Modules that we are JIT'ing from.
uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr)
updateGlobalMapping - Replace an existing mapping for GV with a new address.
bool isSymbolSearchingDisabled() const
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
reference get()
Returns a reference to the stored T value.
Definition Error.h:582
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Type * getParamType(unsigned i) const
Parameter type accessors.
bool isVarArg() const
Type * getReturnType() const
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
JITEventListener - Abstract interface for use by the JIT to notify clients about significant events d...
static JITEventListener * createGDBRegistrationListener()
Represents a symbol in the JIT.
Definition JITSymbol.h:267
JITSymbol findSymbol(const std::string &Name) override
This method returns the address of the specified function or variable.
Definition MCJIT.cpp:678
GenericValue runFunction(Function *F, ArrayRef< GenericValue > ArgValues) override
runFunction - Execute the specified function with the specified arguments, and return the result.
Definition MCJIT.cpp:516
void * getPointerToNamedFunction(StringRef Name, bool AbortOnFailure=true) override
getPointerToNamedFunction - This method returns the address of the specified function by using the dl...
Definition MCJIT.cpp:619
void RegisterJITEventListener(JITEventListener *L) override
Registers a listener to be called back on various events within the JIT.
Definition MCJIT.cpp:641
static ExecutionEngine * createJIT(std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MemMgr, std::shared_ptr< LegacyJITSymbolResolver > Resolver, std::unique_ptr< TargetMachine > TM)
Definition MCJIT.cpp:44
void runStaticConstructorsDestructors(bool isDtors) override
runStaticConstructorsDestructors - This method is used to execute all of the static constructors or d...
Definition MCJIT.cpp:458
Module * findModuleForSymbol(const std::string &Name, bool CheckFunctionsOnly)
Definition MCJIT.cpp:298
void addArchive(object::OwningBinary< object::Archive > O) override
addArchive - Add an Archive to the execution engine.
Definition MCJIT.cpp:142
Function * FindFunctionNamed(StringRef FnName) override
FindFunctionNamed - Search all of the active modules to find the function that defines FnName.
Definition MCJIT.cpp:492
~MCJIT() override
Definition MCJIT.cpp:96
void finalizeObject() override
finalizeObject - ensure the module is fully processed and is usable.
Definition MCJIT.cpp:263
void finalizeLoadedModules()
Definition MCJIT.cpp:243
void notifyObjectLoaded(const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L)
Definition MCJIT.cpp:659
void generateCodeForModule(Module *M) override
generateCodeForModule - Run code generation for the specified module and load it into memory.
Definition MCJIT.cpp:194
uint64_t getFunctionAddress(const std::string &Name) override
getFunctionAddress - Return the address of the specified function.
Definition MCJIT.cpp:407
void addObjectFile(std::unique_ptr< object::ObjectFile > O) override
addObjectFile - Add an ObjectFile to the execution engine.
Definition MCJIT.cpp:124
std::unique_ptr< MemoryBuffer > emitObject(Module *M)
emitObject – Generate a JITed object in memory from the specified module Currently,...
Definition MCJIT.cpp:151
static void Register()
Definition MCJIT.h:290
void UnregisterJITEventListener(JITEventListener *L) override
Definition MCJIT.cpp:648
bool removeModule(Module *M) override
removeModule - Removes a Module from the list of modules, but does not free the module's memory.
Definition MCJIT.cpp:119
JITSymbol findExistingSymbol(const std::string &Name)
Definition MCJIT.cpp:289
GlobalVariable * FindGlobalVariableNamed(StringRef Name, bool AllowInternal=false) override
FindGlobalVariableNamed - Search all of the active modules to find the global variable that defines N...
Definition MCJIT.cpp:504
uint64_t getGlobalValueAddress(const std::string &Name) override
getGlobalValueAddress - Return the address of the specified global value.
Definition MCJIT.cpp:399
uint64_t getSymbolAddress(const std::string &Name, bool CheckFunctionsOnly)
Definition MCJIT.cpp:325
void notifyFreeingObject(const object::ObjectFile &Obj)
Definition MCJIT.cpp:669
virtual void finalizeModule(Module *)
Definition MCJIT.cpp:276
JITSymbol findSymbol(const std::string &Name, bool CheckFunctionsOnly)
Definition MCJIT.cpp:342
void * getPointerToFunction(Function *F) override
getPointerToFunction - The different EE's represent function bodies in different ways.
Definition MCJIT.cpp:416
void setObjectCache(ObjectCache *manager) override
Sets the object manager that MCJIT should use to avoid compilation.
Definition MCJIT.cpp:146
void addModule(std::unique_ptr< Module > M) override
Add a Module to the list of modules that we can JIT from.
Definition MCJIT.cpp:108
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
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
This is the base ObjectCache type which can be provided to an ExecutionEngine for the purpose of avoi...
Definition ObjectCache.h:24
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition Record.h:2271
Information about the loaded object.
Definition RuntimeDyld.h:70
SmallPtrSetIterator< PtrType > iterator
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:597
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
@ VoidTyID
type with no size
Definition Type.h:64
@ FloatTyID
32-bit floating point type
Definition Type.h:59
@ IntegerTyID
Arbitrary bit width integers.
Definition Type.h:71
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
@ X86_FP80TyID
80-bit floating point type (X87)
Definition Type.h:61
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition Type.h:63
@ PointerTyID
Pointers.
Definition Type.h:74
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition Type.h:62
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
TypeID getTypeID() const
Return the type id for the type.
Definition Type.h:138
bool isVoidTy() const
Return true if this is 'void'.
Definition Type.h:141
PassManager manages ModulePassManagers.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
This class is the base class for all object file types.
Definition ObjectFile.h:231
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
void LLVMLinkInMCJIT()
Empty function used to force the linker to link MCJIT.
Definition MCJIT.cpp:40
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition Error.cpp:61
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1781
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
GenericValue PTOGV(void *P)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
constexpr unsigned BitWidth
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
void * GVTOP(const GenericValue &GV)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1106
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:880