LLVM  16.0.0git
ExecutionUtils.cpp
Go to the documentation of this file.
1 //===---- ExecutionUtils.cpp - Utilities for executing functions in Orc ---===//
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 
13 #include "llvm/IR/Constants.h"
14 #include "llvm/IR/Function.h"
15 #include "llvm/IR/GlobalVariable.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/MC/TargetRegistry.h"
21 #include <string>
22 
23 namespace llvm {
24 namespace orc {
25 
27  : InitList(
28  GV ? dyn_cast_or_null<ConstantArray>(GV->getInitializer()) : nullptr),
29  I((InitList && End) ? InitList->getNumOperands() : 0) {
30 }
31 
33  assert(InitList == Other.InitList && "Incomparable iterators.");
34  return I == Other.I;
35 }
36 
38  return !(*this == Other);
39 }
40 
42  ++I;
43  return *this;
44 }
45 
47  CtorDtorIterator Temp = *this;
48  ++I;
49  return Temp;
50 }
51 
53  ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(I));
54  assert(CS && "Unrecognized type in llvm.global_ctors/llvm.global_dtors");
55 
56  Constant *FuncC = CS->getOperand(1);
57  Function *Func = nullptr;
58 
59  // Extract function pointer, pulling off any casts.
60  while (FuncC) {
61  if (Function *F = dyn_cast_or_null<Function>(FuncC)) {
62  Func = F;
63  break;
64  } else if (ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(FuncC)) {
65  if (CE->isCast())
66  FuncC = CE->getOperand(0);
67  else
68  break;
69  } else {
70  // This isn't anything we recognize. Bail out with Func left set to null.
71  break;
72  }
73  }
74 
75  auto *Priority = cast<ConstantInt>(CS->getOperand(0));
76  Value *Data = CS->getNumOperands() == 3 ? CS->getOperand(2) : nullptr;
77  if (Data && !isa<GlobalValue>(Data))
78  Data = nullptr;
79  return Element(Priority->getZExtValue(), Func, Data);
80 }
81 
83  const GlobalVariable *CtorsList = M.getNamedGlobal("llvm.global_ctors");
84  return make_range(CtorDtorIterator(CtorsList, false),
85  CtorDtorIterator(CtorsList, true));
86 }
87 
89  const GlobalVariable *DtorsList = M.getNamedGlobal("llvm.global_dtors");
90  return make_range(CtorDtorIterator(DtorsList, false),
91  CtorDtorIterator(DtorsList, true));
92 }
93 
94 bool StaticInitGVIterator::isStaticInitGlobal(GlobalValue &GV) {
95  if (GV.isDeclaration())
96  return false;
97 
98  if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
99  GV.getName() == "llvm.global_dtors"))
100  return true;
101 
102  if (ObjFmt == Triple::MachO) {
103  // FIXME: These section checks are too strict: We should match first and
104  // second word split by comma.
105  if (GV.hasSection() &&
106  (GV.getSection().startswith("__DATA,__objc_classlist") ||
107  GV.getSection().startswith("__DATA,__objc_selrefs")))
108  return true;
109  }
110 
111  return false;
112 }
113 
115  if (CtorDtors.empty())
116  return;
117 
118  MangleAndInterner Mangle(
119  JD.getExecutionSession(),
120  (*CtorDtors.begin()).Func->getParent()->getDataLayout());
121 
122  for (auto CtorDtor : CtorDtors) {
123  assert(CtorDtor.Func && CtorDtor.Func->hasName() &&
124  "Ctor/Dtor function must be named to be runnable under the JIT");
125 
126  // FIXME: Maybe use a symbol promoter here instead.
127  if (CtorDtor.Func->hasLocalLinkage()) {
128  CtorDtor.Func->setLinkage(GlobalValue::ExternalLinkage);
129  CtorDtor.Func->setVisibility(GlobalValue::HiddenVisibility);
130  }
131 
132  if (CtorDtor.Data && cast<GlobalValue>(CtorDtor.Data)->isDeclaration()) {
133  dbgs() << " Skipping because why now?\n";
134  continue;
135  }
136 
137  CtorDtorsByPriority[CtorDtor.Priority].push_back(
138  Mangle(CtorDtor.Func->getName()));
139  }
140 }
141 
143  using CtorDtorTy = void (*)();
144 
145  SymbolLookupSet LookupSet;
146  for (auto &KV : CtorDtorsByPriority)
147  for (auto &Name : KV.second)
148  LookupSet.add(Name);
149  assert(!LookupSet.containsDuplicates() &&
150  "Ctor/Dtor list contains duplicates");
151 
152  auto &ES = JD.getExecutionSession();
153  if (auto CtorDtorMap = ES.lookup(
155  std::move(LookupSet))) {
156  for (auto &KV : CtorDtorsByPriority) {
157  for (auto &Name : KV.second) {
158  assert(CtorDtorMap->count(Name) && "No entry for Name");
159  auto CtorDtor = reinterpret_cast<CtorDtorTy>(
160  static_cast<uintptr_t>((*CtorDtorMap)[Name].getAddress()));
161  CtorDtor();
162  }
163  }
164  CtorDtorsByPriority.clear();
165  return Error::success();
166  } else
167  return CtorDtorMap.takeError();
168 }
169 
171  auto& CXXDestructorDataPairs = DSOHandleOverride;
172  for (auto &P : CXXDestructorDataPairs)
173  P.first(P.second);
174  CXXDestructorDataPairs.clear();
175 }
176 
178  void *Arg,
179  void *DSOHandle) {
180  auto& CXXDestructorDataPairs =
181  *reinterpret_cast<CXXDestructorDataPairList*>(DSOHandle);
182  CXXDestructorDataPairs.push_back(std::make_pair(Destructor, Arg));
183  return 0;
184 }
185 
187  MangleAndInterner &Mangle) {
188  SymbolMap RuntimeInterposes;
189  RuntimeInterposes[Mangle("__dso_handle")] =
192  RuntimeInterposes[Mangle("__cxa_atexit")] =
195 
196  return JD.define(absoluteSymbols(std::move(RuntimeInterposes)));
197 }
198 
199 void ItaniumCXAAtExitSupport::registerAtExit(void (*F)(void *), void *Ctx,
200  void *DSOHandle) {
201  std::lock_guard<std::mutex> Lock(AtExitsMutex);
202  AtExitRecords[DSOHandle].push_back({F, Ctx});
203 }
204 
205 void ItaniumCXAAtExitSupport::runAtExits(void *DSOHandle) {
206  std::vector<AtExitRecord> AtExitsToRun;
207 
208  {
209  std::lock_guard<std::mutex> Lock(AtExitsMutex);
210  auto I = AtExitRecords.find(DSOHandle);
211  if (I != AtExitRecords.end()) {
212  AtExitsToRun = std::move(I->second);
213  AtExitRecords.erase(I);
214  }
215  }
216 
217  while (!AtExitsToRun.empty()) {
218  AtExitsToRun.back().F(AtExitsToRun.back().Ctx);
219  AtExitsToRun.pop_back();
220  }
221 }
222 
225  : Dylib(std::move(Dylib)), Allow(std::move(Allow)),
227 
231  std::string ErrMsg;
232  auto Lib = sys::DynamicLibrary::getPermanentLibrary(FileName, &ErrMsg);
233  if (!Lib.isValid())
234  return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
235  return std::make_unique<DynamicLibrarySearchGenerator>(
236  std::move(Lib), GlobalPrefix, std::move(Allow));
237 }
238 
241  JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
242  orc::SymbolMap NewSymbols;
243 
244  bool HasGlobalPrefix = (GlobalPrefix != '\0');
245 
246  for (auto &KV : Symbols) {
247  auto &Name = KV.first;
248 
249  if ((*Name).empty())
250  continue;
251 
252  if (Allow && !Allow(Name))
253  continue;
254 
255  if (HasGlobalPrefix && (*Name).front() != GlobalPrefix)
256  continue;
257 
258  std::string Tmp((*Name).data() + HasGlobalPrefix,
259  (*Name).size() - HasGlobalPrefix);
260  if (void *Addr = Dylib.getAddressOfSymbol(Tmp.c_str())) {
261  NewSymbols[Name] = JITEvaluatedSymbol(
262  static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(Addr)),
264  }
265  }
266 
267  if (NewSymbols.empty())
268  return Error::success();
269 
270  return JD.define(absoluteSymbols(std::move(NewSymbols)));
271 }
272 
275  ObjectLayer &L, const char *FileName,
276  GetObjectFileInterface GetObjFileInterface) {
277  auto ArchiveBuffer = MemoryBuffer::getFile(FileName);
278 
279  if (!ArchiveBuffer)
280  return createFileError(FileName, ArchiveBuffer.getError());
281 
282  return Create(L, std::move(*ArchiveBuffer), std::move(GetObjFileInterface));
283 }
284 
287  ObjectLayer &L, const char *FileName, const Triple &TT,
288  GetObjectFileInterface GetObjFileInterface) {
289 
290  auto B = object::createBinary(FileName);
291  if (!B)
292  return createFileError(FileName, B.takeError());
293 
294  // If this is a regular archive then create an instance from it.
295  if (isa<object::Archive>(B->getBinary()))
296  return Create(L, std::move(B->takeBinary().second),
297  std::move(GetObjFileInterface));
298 
299  // If this is a universal binary then search for a slice matching the given
300  // Triple.
301  if (auto *UB = cast<object::MachOUniversalBinary>(B->getBinary())) {
302  for (const auto &Obj : UB->objects()) {
303  auto ObjTT = Obj.getTriple();
304  if (ObjTT.getArch() == TT.getArch() &&
305  ObjTT.getSubArch() == TT.getSubArch() &&
306  (TT.getVendor() == Triple::UnknownVendor ||
307  ObjTT.getVendor() == TT.getVendor())) {
308  // We found a match. Create an instance from a buffer covering this
309  // slice.
310  auto SliceBuffer = MemoryBuffer::getFileSlice(FileName, Obj.getSize(),
311  Obj.getOffset());
312  if (!SliceBuffer)
313  return make_error<StringError>(
314  Twine("Could not create buffer for ") + TT.str() + " slice of " +
315  FileName + ": [ " + formatv("{0:x}", Obj.getOffset()) +
316  " .. " + formatv("{0:x}", Obj.getOffset() + Obj.getSize()) +
317  ": " + SliceBuffer.getError().message(),
318  SliceBuffer.getError());
319  return Create(L, std::move(*SliceBuffer),
320  std::move(GetObjFileInterface));
321  }
322  }
323 
324  return make_error<StringError>(Twine("Universal binary ") + FileName +
325  " does not contain a slice for " +
326  TT.str(),
328  }
329 
330  return make_error<StringError>(Twine("Unrecognized file type for ") +
331  FileName,
333 }
334 
337  ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
338  GetObjectFileInterface GetObjFileInterface) {
339  Error Err = Error::success();
340 
341  std::unique_ptr<StaticLibraryDefinitionGenerator> ADG(
343  L, std::move(ArchiveBuffer), std::move(GetObjFileInterface), Err));
344 
345  if (Err)
346  return std::move(Err);
347 
348  return std::move(ADG);
349 }
350 
353  JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
354  // Don't materialize symbols from static archives unless this is a static
355  // lookup.
356  if (K != LookupKind::Static)
357  return Error::success();
358 
359  // Bail out early if we've already freed the archive.
360  if (!Archive)
361  return Error::success();
362 
364 
365  for (const auto &KV : Symbols) {
366  const auto &Name = KV.first;
367  if (!ObjectFilesMap.count(Name))
368  continue;
369  auto ChildBuffer = ObjectFilesMap[Name];
370  ChildBufferInfos.insert(
371  {ChildBuffer.getBuffer(), ChildBuffer.getBufferIdentifier()});
372  }
373 
374  for (auto ChildBufferInfo : ChildBufferInfos) {
375  MemoryBufferRef ChildBufferRef(ChildBufferInfo.first,
376  ChildBufferInfo.second);
377 
378  auto I = GetObjFileInterface(L.getExecutionSession(), ChildBufferRef);
379  if (!I)
380  return I.takeError();
381 
382  if (auto Err = L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef, false),
383  std::move(*I)))
384  return Err;
385  }
386 
387  return Error::success();
388 }
389 
390 Error StaticLibraryDefinitionGenerator::buildObjectFilesMap() {
392  DenseSet<uint64_t> Visited;
393  DenseSet<uint64_t> Excluded;
394  for (auto &S : Archive->symbols()) {
395  StringRef SymName = S.getName();
396  auto Member = S.getMember();
397  if (!Member)
398  return Member.takeError();
399  auto DataOffset = Member->getDataOffset();
400  if (!Visited.count(DataOffset)) {
401  Visited.insert(DataOffset);
402  auto Child = Member->getAsBinary();
403  if (!Child)
404  return Child.takeError();
405  if ((*Child)->isCOFFImportFile()) {
406  ImportedDynamicLibraries.insert((*Child)->getFileName().str());
407  Excluded.insert(DataOffset);
408  continue;
409  }
410  MemoryBuffers[DataOffset] = (*Child)->getMemoryBufferRef();
411  }
412  if (!Excluded.count(DataOffset))
413  ObjectFilesMap[L.getExecutionSession().intern(SymName)] =
414  MemoryBuffers[DataOffset];
415  }
416 
417  return Error::success();
418 }
419 
420 StaticLibraryDefinitionGenerator::StaticLibraryDefinitionGenerator(
421  ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
422  GetObjectFileInterface GetObjFileInterface, Error &Err)
423  : L(L), GetObjFileInterface(std::move(GetObjFileInterface)),
424  ArchiveBuffer(std::move(ArchiveBuffer)),
425  Archive(std::make_unique<object::Archive>(*this->ArchiveBuffer, Err)) {
426  ErrorAsOutParameter _(&Err);
427  if (!this->GetObjFileInterface)
428  this->GetObjFileInterface = getObjectFileInterface;
429  if (!Err)
430  Err = buildObjectFilesMap();
431 }
432 
433 std::unique_ptr<DLLImportDefinitionGenerator>
435  ObjectLinkingLayer &L) {
436  return std::unique_ptr<DLLImportDefinitionGenerator>(
437  new DLLImportDefinitionGenerator(ES, L));
438 }
439 
442  JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) {
443  JITDylibSearchOrder LinkOrder;
444  JD.withLinkOrderDo([&](const JITDylibSearchOrder &LO) {
445  LinkOrder.reserve(LO.size());
446  for (auto &KV : LO) {
447  if (KV.first == &JD)
448  continue;
449  LinkOrder.push_back(KV);
450  }
451  });
452 
453  // FIXME: if regular symbol name start with __imp_ we have to issue lookup of
454  // both __imp_ and stripped name and use the lookup information to resolve the
455  // real symbol name.
456  SymbolLookupSet LookupSet;
458  for (auto &KV : Symbols) {
459  StringRef Deinterned = *KV.first;
460  if (Deinterned.startswith(getImpPrefix()))
461  Deinterned = Deinterned.drop_front(StringRef(getImpPrefix()).size());
462  // Don't degrade the required state
463  if (ToLookUpSymbols.count(Deinterned) &&
464  ToLookUpSymbols[Deinterned] == SymbolLookupFlags::RequiredSymbol)
465  continue;
466  ToLookUpSymbols[Deinterned] = KV.second;
467  }
468 
469  for (auto &KV : ToLookUpSymbols)
470  LookupSet.add(ES.intern(KV.first), KV.second);
471 
472  auto Resolved =
473  ES.lookup(LinkOrder, LookupSet, LookupKind::DLSym, SymbolState::Resolved);
474  if (!Resolved)
475  return Resolved.takeError();
476 
477  auto G = createStubsGraph(*Resolved);
478  if (!G)
479  return G.takeError();
480  return L.add(JD, std::move(*G));
481 }
482 
484 DLLImportDefinitionGenerator::getTargetPointerSize(const Triple &TT) {
485  switch (TT.getArch()) {
486  case Triple::x86_64:
487  return 8;
488  default:
489  return make_error<StringError>(
490  "architecture unsupported by DLLImportDefinitionGenerator",
492  }
493 }
494 
495 Expected<support::endianness>
496 DLLImportDefinitionGenerator::getTargetEndianness(const Triple &TT) {
497  switch (TT.getArch()) {
498  case Triple::x86_64:
500  default:
501  return make_error<StringError>(
502  "architecture unsupported by DLLImportDefinitionGenerator",
504  }
505 }
506 
507 Expected<std::unique_ptr<jitlink::LinkGraph>>
508 DLLImportDefinitionGenerator::createStubsGraph(const SymbolMap &Resolved) {
510  auto PointerSize = getTargetEndianness(TT);
511  if (!PointerSize)
512  return PointerSize.takeError();
513  auto Endianness = getTargetEndianness(TT);
514  if (!Endianness)
515  return Endianness.takeError();
516 
517  auto G = std::make_unique<jitlink::LinkGraph>(
518  "<DLLIMPORT_STUBS>", TT, *PointerSize, *Endianness,
520  jitlink::Section &Sec =
521  G->createSection(getSectionName(), MemProt::Read | MemProt::Exec);
522 
523  for (auto &KV : Resolved) {
524  jitlink::Symbol &Target = G->addAbsoluteSymbol(
525  *KV.first, ExecutorAddr(KV.second.getAddress()), *PointerSize,
527 
528  // Create __imp_ symbol
529  jitlink::Symbol &Ptr =
531  auto NameCopy = G->allocateString(Twine(getImpPrefix()) + *KV.first);
532  StringRef NameCopyRef = StringRef(NameCopy.data(), NameCopy.size());
533  Ptr.setName(NameCopyRef);
534  Ptr.setLinkage(jitlink::Linkage::Strong);
535  Ptr.setScope(jitlink::Scope::Default);
536 
537  // Create PLT stub
538  // FIXME: check PLT stub of data symbol is not accessed
539  jitlink::Block &StubBlock =
541  G->addDefinedSymbol(StubBlock, 0, *KV.first, StubBlock.getSize(),
543  false);
544  }
545 
546  return std::move(G);
547 }
548 
549 } // End namespace orc.
550 } // End namespace llvm.
llvm::AArch64CC::LO
@ LO
Definition: AArch64BaseInfo.h:258
llvm::orc::JITDylib::withLinkOrderDo
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
Definition: Core.h:1799
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::orc::JITDylib
Represents a JIT'd dynamic library.
Definition: Core.h:953
llvm::msgpack::Endianness
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::ARM::PredBlockMask::TT
@ TT
llvm::orc::CtorDtorRunner::add
void add(iterator_range< CtorDtorIterator > CtorDtors)
Definition: ExecutionUtils.cpp:114
llvm::unique_function< Expected< MaterializationUnit::Interface >(ExecutionSession &ES, MemoryBufferRef ObjBuffer)>
llvm::sys::DynamicLibrary::getAddressOfSymbol
void * getAddressOfSymbol(const char *symbolName)
Searches through the library for the symbol symbolName.
Definition: DynamicLibrary.cpp:212
llvm::orc::getConstructors
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
Definition: ExecutionUtils.cpp:82
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
llvm::Function
Definition: Function.h:60
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:175
llvm::orc::LookupKind::Static
@ Static
llvm::orc::ObjectLayer::add
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > O, MaterializationUnit::Interface I)
Adds a MaterializationUnit for the object file in the given memory buffer to the JITDylib for the giv...
Definition: Layer.cpp:163
llvm::Value::hasName
bool hasName() const
Definition: Value.h:261
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
GlobalPrefix
@ GlobalPrefix
Definition: AsmWriter.cpp:349
Module.h
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
llvm::GlobalValue::hasSection
bool hasSection() const
Definition: GlobalValue.h:286
llvm::AMDGPU::Exp::Target
Target
Definition: SIDefines.h:852
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::orc::LocalCXXRuntimeOverridesBase::DSOHandleOverride
CXXDestructorDataPairList DSOHandleOverride
Definition: ExecutionUtils.h:186
llvm::orc::LookupKind
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:149
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::detail::DenseSetImpl::count
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
Layer.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::orc::CtorDtorIterator::operator==
bool operator==(const CtorDtorIterator &Other) const
Test iterators for equality.
Definition: ExecutionUtils.cpp:32
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, Optional< Align > Alignment=None)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:248
llvm::JITEvaluatedSymbol
Represents a symbol that has been evaluated to an address already.
Definition: JITSymbol.h:229
llvm::sys::DynamicLibrary
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
Definition: DynamicLibrary.h:33
ExecutionUtils.h
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::orc::CtorDtorIterator
This iterator provides a convenient way to iterate over the elements of an llvm.global_ctors/llvm....
Definition: ExecutionUtils.h:48
llvm::GlobalValue::getSection
StringRef getSection() const
Definition: Globals.cpp:166
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:187
llvm::orc::DynamicLibrarySearchGenerator::DynamicLibrarySearchGenerator
DynamicLibrarySearchGenerator(sys::DynamicLibrary Dylib, char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate())
Create a DynamicLibrarySearchGenerator that searches for symbols in the given sys::DynamicLibrary.
Definition: ExecutionUtils.cpp:223
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::orc::DLLImportDefinitionGenerator::Create
static std::unique_ptr< DLLImportDefinitionGenerator > Create(ExecutionSession &ES, ObjectLinkingLayer &L)
Creates a DLLImportDefinitionGenerator instance.
Definition: ExecutionUtils.cpp:434
llvm::MemoryBuffer::getMemBuffer
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
Definition: MemoryBuffer.cpp:120
TargetMachine.h
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:266
llvm::StringRef::startswith
bool startswith(StringRef Prefix) const
Definition: StringRef.h:260
Constants.h
llvm::createFileError
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1319
llvm::orc::SymbolLookupSet::containsDuplicates
bool containsDuplicates()
Returns true if this set contains any duplicates.
Definition: Core.h:363
llvm::support::little
@ little
Definition: Endian.h:27
llvm::sys::DynamicLibrary::getPermanentLibrary
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path using the library load operatio...
Definition: DynamicLibrary.cpp:165
llvm::orc::LocalCXXRuntimeOverrides::enable
Error enable(JITDylib &JD, MangleAndInterner &Mangler)
Definition: ExecutionUtils.cpp:186
llvm::orc::MemProt::Read
@ Read
MachOUniversal.h
llvm::SubDirectoryType::Lib
@ Lib
llvm::orc::SymbolMap
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
Definition: Core.h:113
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::ConstantArray
ConstantArray - Constant Array Declarations.
Definition: Constants.h:410
llvm::orc::ExecutionSession::intern
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1416
llvm::orc::ObjectLayer::getExecutionSession
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
Definition: Layer.h:141
llvm::orc::ObjectLayer
Interface for Layers that accept object files.
Definition: Layer.h:133
llvm::orc::LookupKind::DLSym
@ DLSym
llvm::orc::SymbolLookupSet::add
SymbolLookupSet & add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Definition: Core.h:236
llvm::iterator_range::empty
bool empty() const
Definition: iterator_range.h:46
FormatVariadic.h
llvm::orc::LocalCXXRuntimeOverridesBase::runDestructors
void runDestructors()
Run any destructors recorded by the overriden __cxa_atexit function (CXAAtExitOverride).
Definition: ExecutionUtils.cpp:170
llvm::orc::DynamicLibrarySearchGenerator::tryToGenerate
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Definition: ExecutionUtils.cpp:239
llvm::orc::LocalCXXRuntimeOverridesBase::CXXDestructorDataPairList
std::vector< CXXDestructorDataPair > CXXDestructorDataPairList
Definition: ExecutionUtils.h:185
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::orc::LocalCXXRuntimeOverridesBase::DestructorPtr
void(*)(void *) DestructorPtr
Definition: ExecutionUtils.h:183
llvm::GlobalValue
Definition: GlobalValue.h:44
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::orc::getDestructors
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
Definition: ExecutionUtils.cpp:88
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::DenseMap< SymbolStringPtr, JITEvaluatedSymbol >
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::orc::LocalCXXRuntimeOverridesBase::CXAAtExitOverride
static int CXAAtExitOverride(DestructorPtr Destructor, void *Arg, void *DSOHandle)
Definition: ExecutionUtils.cpp:177
llvm::orc::CtorDtorIterator::Element
Accessor for an element of the global_ctors/global_dtors array.
Definition: ExecutionUtils.h:54
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
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:1861
llvm::orc::CtorDtorIterator::operator!=
bool operator!=(const CtorDtorIterator &Other) const
Test iterators for inequality.
Definition: ExecutionUtils.cpp:37
Ptr
@ Ptr
Definition: TargetLibraryInfo.cpp:60
llvm::orc::StaticLibraryDefinitionGenerator
A utility class to expose symbols from a static library.
Definition: ExecutionUtils.h:260
llvm::orc::JITDylibSearchOrder
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:154
llvm::orc::ExecutionSession::getExecutorProcessControl
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition: Core.h:1408
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::DenseMapBase::empty
bool empty() const
Definition: DenseMap.h:98
llvm::ConstantStruct
Definition: Constants.h:442
_
#define _
Definition: HexagonMCCodeEmitter.cpp:47
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1715
llvm::orc::CtorDtorIterator::operator++
CtorDtorIterator & operator++()
Pre-increment iterator.
Definition: ExecutionUtils.cpp:41
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::orc::LookupState
Wraps state for a lookup-in-progress.
Definition: Core.h:893
llvm::Triple::UnknownVendor
@ UnknownVendor
Definition: Triple.h:166
llvm::orc::StaticLibraryDefinitionGenerator::Load
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibraryDefinitionGenerator from the given path.
Definition: ExecutionUtils.cpp:274
llvm::orc::ItaniumCXAAtExitSupport::runAtExits
void runAtExits(void *DSOHandle)
Definition: ExecutionUtils.cpp:205
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:308
for
this could be done in SelectionDAGISel along with other special for
Definition: README.txt:104
x86_64.h
llvm::orc::ItaniumCXAAtExitSupport::registerAtExit
void registerAtExit(void(*F)(void *), void *Ctx, void *DSOHandle)
Definition: ExecutionUtils.cpp:199
llvm::orc::ObjectLinkingLayer
An ObjectLayer implementation built on JITLink.
Definition: ObjectLinkingLayer.h:50
llvm::orc::MangleAndInterner
Mangles symbol names then uniques them in the context of an ExecutionSession.
Definition: Mangling.h:26
llvm::MemoryBuffer::getFileSlice
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile=false, Optional< Align > Alignment=None)
Map a subrange of the specified file as a MemoryBuffer.
Definition: MemoryBuffer.cpp:164
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:972
std
Definition: BitVector.h:851
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::orc::ExecutorProcessControl::getTargetTriple
const Triple & getTargetTriple() const
Return the Triple for the target process.
Definition: ExecutorProcessControl.h:201
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
GlobalVariable.h
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1365
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:264
llvm::Triple::MachO
@ MachO
Definition: Triple.h:285
Function.h
llvm::orc::StaticLibraryDefinitionGenerator::tryToGenerate
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Definition: ExecutionUtils.cpp:351
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:763
llvm::orc::CtorDtorIterator::CtorDtorIterator
CtorDtorIterator(const GlobalVariable *GV, bool End)
Construct an iterator instance.
Definition: ExecutionUtils.cpp:26
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::orc::CtorDtorIterator::operator*
Element operator*() const
Dereference iterator.
Definition: ExecutionUtils.cpp:52
llvm::User::getNumOperands
unsigned getNumOperands() const
Definition: User.h:191
llvm::orc::JITDylib::define
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:1806
llvm::orc::DynamicLibrarySearchGenerator::SymbolPredicate
std::function< bool(const SymbolStringPtr &)> SymbolPredicate
Definition: ExecutionUtils.h:219
llvm::orc::DynamicLibrarySearchGenerator::Load
static Expected< std::unique_ptr< DynamicLibrarySearchGenerator > > Load(const char *FileName, char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate())
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
Definition: ExecutionUtils.cpp:229
llvm::TPLoop::Allow
@ Allow
Definition: ARMTargetTransformInfo.h:53
llvm::orc::ExecutionSession::lookup
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Definition: Core.cpp:2076
llvm::orc::getObjectFileInterface
Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
Definition: ObjectFileInterface.cpp:274
llvm::orc::JITDylib::getExecutionSession
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Definition: Core.h:973
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::orc::LocalCXXRuntimeOverridesBase::toTargetAddress
JITTargetAddress toTargetAddress(PtrTy *P)
Definition: ExecutionUtils.h:179
llvm::object::createBinary
Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
Definition: Binary.cpp:45
llvm::orc::StaticLibraryDefinitionGenerator::Create
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibrarySearchGenerator from the given memory buffer.
Definition: ExecutionUtils.cpp:336
llvm::orc::JITDylibLookupFlags
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition: Core.h:127
llvm::orc::SymbolState::Resolved
@ Resolved
Queried, materialization begun.
llvm::orc::MemProt::Exec
@ Exec
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::orc::CtorDtorRunner::run
Error run()
Definition: ExecutionUtils.cpp:142
llvm::orc::JITDylibLookupFlags::MatchAllSymbols
@ MatchAllSymbols
llvm::orc::SymbolLookupFlags::RequiredSymbol
@ RequiredSymbol
TargetRegistry.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::orc::DLLImportDefinitionGenerator::tryToGenerate
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Definition: ExecutionUtils.cpp:440
llvm::orc::makeJITDylibSearchOrder
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:158
llvm::StringRef::drop_front
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:602
llvm::iterator_range::begin
IteratorT begin() const
Definition: iterator_range.h:44
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1251
ObjectFileInterface.h
llvm::JITSymbolFlags::Exported
@ Exported
Definition: JITSymbol.h:85
llvm::orc::DLLImportDefinitionGenerator
A utility class to create COFF dllimport GOT symbols (__imp_*) and PLT stubs.
Definition: ExecutionUtils.h:325
llvm::dyn_cast_or_null
auto dyn_cast_or_null(const Y &Val)
Definition: Casting.h:758