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