LLVM  14.0.0git
IndirectionUtils.h
Go to the documentation of this file.
1 //===- IndirectionUtils.h - Utilities for adding indirections ---*- C++ -*-===//
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 // Contains utilities for adding indirections and breaking up modules.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
14 #define LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
15 
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/Error.h"
22 #include "llvm/Support/Memory.h"
23 #include "llvm/Support/Process.h"
25 #include <algorithm>
26 #include <cassert>
27 #include <cstdint>
28 #include <functional>
29 #include <future>
30 #include <map>
31 #include <memory>
32 #include <system_error>
33 #include <utility>
34 #include <vector>
35 
36 namespace llvm {
37 
38 class Constant;
39 class Function;
40 class FunctionType;
41 class GlobalAlias;
42 class GlobalVariable;
43 class Module;
44 class PointerType;
45 class Triple;
46 class Twine;
47 class Value;
48 class MCDisassembler;
49 class MCInstrAnalysis;
50 
51 namespace jitlink {
52 class LinkGraph;
53 class Symbol;
54 } // namespace jitlink
55 
56 namespace orc {
57 
58 /// Base class for pools of compiler re-entry trampolines.
59 /// These trampolines are callable addresses that save all register state
60 /// before calling a supplied function to return the trampoline landing
61 /// address, then restore all state before jumping to that address. They
62 /// are used by various ORC APIs to support lazy compilation
64 public:
67 
69  JITTargetAddress TrampolineAddr,
70  NotifyLandingResolvedFunction OnLandingResolved) const>;
71 
72  virtual ~TrampolinePool();
73 
74  /// Get an available trampoline address.
75  /// Returns an error if no trampoline can be created.
77  std::lock_guard<std::mutex> Lock(TPMutex);
78  if (AvailableTrampolines.empty()) {
79  if (auto Err = grow())
80  return std::move(Err);
81  }
82  assert(!AvailableTrampolines.empty() && "Failed to grow trampoline pool");
83  auto TrampolineAddr = AvailableTrampolines.back();
84  AvailableTrampolines.pop_back();
85  return TrampolineAddr;
86  }
87 
88  /// Returns the given trampoline to the pool for re-use.
89  void releaseTrampoline(JITTargetAddress TrampolineAddr) {
90  std::lock_guard<std::mutex> Lock(TPMutex);
91  AvailableTrampolines.push_back(TrampolineAddr);
92  }
93 
94 protected:
95  virtual Error grow() = 0;
96 
97  std::mutex TPMutex;
98  std::vector<JITTargetAddress> AvailableTrampolines;
99 };
100 
101 /// A trampoline pool for trampolines within the current process.
102 template <typename ORCABI> class LocalTrampolinePool : public TrampolinePool {
103 public:
104  /// Creates a LocalTrampolinePool with the given RunCallback function.
105  /// Returns an error if this function is unable to correctly allocate, write
106  /// and protect the resolver code block.
108  Create(ResolveLandingFunction ResolveLanding) {
109  Error Err = Error::success();
110 
111  auto LTP = std::unique_ptr<LocalTrampolinePool>(
112  new LocalTrampolinePool(std::move(ResolveLanding), Err));
113 
114  if (Err)
115  return std::move(Err);
116  return std::move(LTP);
117  }
118 
119 private:
120  static JITTargetAddress reenter(void *TrampolinePoolPtr, void *TrampolineId) {
122  static_cast<LocalTrampolinePool *>(TrampolinePoolPtr);
123 
124  std::promise<JITTargetAddress> LandingAddressP;
125  auto LandingAddressF = LandingAddressP.get_future();
126 
127  TrampolinePool->ResolveLanding(pointerToJITTargetAddress(TrampolineId),
128  [&](JITTargetAddress LandingAddress) {
129  LandingAddressP.set_value(LandingAddress);
130  });
131  return LandingAddressF.get();
132  }
133 
134  LocalTrampolinePool(ResolveLandingFunction ResolveLanding, Error &Err)
135  : ResolveLanding(std::move(ResolveLanding)) {
136 
137  ErrorAsOutParameter _(&Err);
138 
139  /// Try to set up the resolver block.
140  std::error_code EC;
141  ResolverBlock = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
142  ORCABI::ResolverCodeSize, nullptr,
144  if (EC) {
145  Err = errorCodeToError(EC);
146  return;
147  }
148 
149  ORCABI::writeResolverCode(static_cast<char *>(ResolverBlock.base()),
150  pointerToJITTargetAddress(ResolverBlock.base()),
151  pointerToJITTargetAddress(&reenter),
153 
157  if (EC) {
158  Err = errorCodeToError(EC);
159  return;
160  }
161  }
162 
163  Error grow() override {
164  assert(AvailableTrampolines.empty() && "Growing prematurely?");
165 
166  std::error_code EC;
167  auto TrampolineBlock =
168  sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
171  if (EC)
172  return errorCodeToError(EC);
173 
174  unsigned NumTrampolines =
176  ORCABI::TrampolineSize;
177 
178  char *TrampolineMem = static_cast<char *>(TrampolineBlock.base());
179  ORCABI::writeTrampolines(
180  TrampolineMem, pointerToJITTargetAddress(TrampolineMem),
181  pointerToJITTargetAddress(ResolverBlock.base()), NumTrampolines);
182 
183  for (unsigned I = 0; I < NumTrampolines; ++I)
185  TrampolineMem + (I * ORCABI::TrampolineSize)));
186 
187  if (auto EC = sys::Memory::protectMappedMemory(
188  TrampolineBlock.getMemoryBlock(),
190  return errorCodeToError(EC);
191 
192  TrampolineBlocks.push_back(std::move(TrampolineBlock));
193  return Error::success();
194  }
195 
196  ResolveLandingFunction ResolveLanding;
197 
198  sys::OwningMemoryBlock ResolverBlock;
199  std::vector<sys::OwningMemoryBlock> TrampolineBlocks;
200 };
201 
202 /// Target-independent base class for compile callback management.
204 public:
206 
207  virtual ~JITCompileCallbackManager() = default;
208 
209  /// Reserve a compile callback.
211 
212  /// Execute the callback for the given trampoline id. Called by the JIT
213  /// to compile functions on demand.
215 
216 protected:
217  /// Construct a JITCompileCallbackManager.
218  JITCompileCallbackManager(std::unique_ptr<TrampolinePool> TP,
219  ExecutionSession &ES,
220  JITTargetAddress ErrorHandlerAddress)
221  : TP(std::move(TP)), ES(ES),
222  CallbacksJD(ES.createBareJITDylib("<Callbacks>")),
223  ErrorHandlerAddress(ErrorHandlerAddress) {}
224 
225  void setTrampolinePool(std::unique_ptr<TrampolinePool> TP) {
226  this->TP = std::move(TP);
227  }
228 
229 private:
230  std::mutex CCMgrMutex;
231  std::unique_ptr<TrampolinePool> TP;
232  ExecutionSession &ES;
233  JITDylib &CallbacksJD;
234  JITTargetAddress ErrorHandlerAddress;
235  std::map<JITTargetAddress, SymbolStringPtr> AddrToSymbol;
236  size_t NextCallbackId = 0;
237 };
238 
239 /// Manage compile callbacks for in-process JITs.
240 template <typename ORCABI>
242 public:
243  /// Create a new LocalJITCompileCallbackManager.
245  Create(ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress) {
246  Error Err = Error::success();
247  auto CCMgr = std::unique_ptr<LocalJITCompileCallbackManager>(
248  new LocalJITCompileCallbackManager(ES, ErrorHandlerAddress, Err));
249  if (Err)
250  return std::move(Err);
251  return std::move(CCMgr);
252  }
253 
254 private:
255  /// Construct a InProcessJITCompileCallbackManager.
256  /// @param ErrorHandlerAddress The address of an error handler in the target
257  /// process to be used if a compile callback fails.
259  JITTargetAddress ErrorHandlerAddress,
260  Error &Err)
261  : JITCompileCallbackManager(nullptr, ES, ErrorHandlerAddress) {
262  using NotifyLandingResolvedFunction =
264 
265  ErrorAsOutParameter _(&Err);
267  [this](JITTargetAddress TrampolineAddr,
268  NotifyLandingResolvedFunction NotifyLandingResolved) {
269  NotifyLandingResolved(executeCompileCallback(TrampolineAddr));
270  });
271 
272  if (!TP) {
273  Err = TP.takeError();
274  return;
275  }
276 
278  }
279 };
280 
281 /// Base class for managing collections of named indirect stubs.
283 public:
284  /// Map type for initializing the manager. See init.
286 
287  virtual ~IndirectStubsManager() = default;
288 
289  /// Create a single stub with the given name, target address and flags.
290  virtual Error createStub(StringRef StubName, JITTargetAddress StubAddr,
291  JITSymbolFlags StubFlags) = 0;
292 
293  /// Create StubInits.size() stubs with the given names, target
294  /// addresses, and flags.
295  virtual Error createStubs(const StubInitsMap &StubInits) = 0;
296 
297  /// Find the stub with the given name. If ExportedStubsOnly is true,
298  /// this will only return a result if the stub's flags indicate that it
299  /// is exported.
300  virtual JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) = 0;
301 
302  /// Find the implementation-pointer for the stub.
304 
305  /// Change the value of the implementation pointer for the stub.
306  virtual Error updatePointer(StringRef Name, JITTargetAddress NewAddr) = 0;
307 
308 private:
309  virtual void anchor();
310 };
311 
312 template <typename ORCABI> class LocalIndirectStubsInfo {
313 public:
314  LocalIndirectStubsInfo(unsigned NumStubs, sys::OwningMemoryBlock StubsMem)
315  : NumStubs(NumStubs), StubsMem(std::move(StubsMem)) {}
316 
317  static Expected<LocalIndirectStubsInfo> create(unsigned MinStubs,
318  unsigned PageSize) {
319  auto ISAS = getIndirectStubsBlockSizes<ORCABI>(MinStubs, PageSize);
320 
321  assert((ISAS.StubBytes % PageSize == 0) &&
322  "StubBytes is not a page size multiple");
323  uint64_t PointerAlloc = alignTo(ISAS.PointerBytes, PageSize);
324 
325  // Allocate memory for stubs and pointers in one call.
326  std::error_code EC;
327  auto StubsAndPtrsMem =
329  ISAS.StubBytes + PointerAlloc, nullptr,
331  if (EC)
332  return errorCodeToError(EC);
333 
334  sys::MemoryBlock StubsBlock(StubsAndPtrsMem.base(), ISAS.StubBytes);
335  auto StubsBlockMem = static_cast<char *>(StubsAndPtrsMem.base());
336  auto PtrBlockAddress =
337  pointerToJITTargetAddress(StubsBlockMem) + ISAS.StubBytes;
338 
339  ORCABI::writeIndirectStubsBlock(StubsBlockMem,
340  pointerToJITTargetAddress(StubsBlockMem),
341  PtrBlockAddress, ISAS.NumStubs);
342 
343  if (auto EC = sys::Memory::protectMappedMemory(
345  return errorCodeToError(EC);
346 
347  return LocalIndirectStubsInfo(ISAS.NumStubs, std::move(StubsAndPtrsMem));
348  }
349 
350  unsigned getNumStubs() const { return NumStubs; }
351 
352  void *getStub(unsigned Idx) const {
353  return static_cast<char *>(StubsMem.base()) + Idx * ORCABI::StubSize;
354  }
355 
356  void **getPtr(unsigned Idx) const {
357  char *PtrsBase =
358  static_cast<char *>(StubsMem.base()) + NumStubs * ORCABI::StubSize;
359  return reinterpret_cast<void **>(PtrsBase) + Idx;
360  }
361 
362 private:
363  unsigned NumStubs = 0;
364  sys::OwningMemoryBlock StubsMem;
365 };
366 
367 /// IndirectStubsManager implementation for the host architecture, e.g.
368 /// OrcX86_64. (See OrcArchitectureSupport.h).
369 template <typename TargetT>
371 public:
373  JITSymbolFlags StubFlags) override {
374  std::lock_guard<std::mutex> Lock(StubsMutex);
375  if (auto Err = reserveStubs(1))
376  return Err;
377 
378  createStubInternal(StubName, StubAddr, StubFlags);
379 
380  return Error::success();
381  }
382 
383  Error createStubs(const StubInitsMap &StubInits) override {
384  std::lock_guard<std::mutex> Lock(StubsMutex);
385  if (auto Err = reserveStubs(StubInits.size()))
386  return Err;
387 
388  for (auto &Entry : StubInits)
389  createStubInternal(Entry.first(), Entry.second.first,
390  Entry.second.second);
391 
392  return Error::success();
393  }
394 
395  JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
396  std::lock_guard<std::mutex> Lock(StubsMutex);
397  auto I = StubIndexes.find(Name);
398  if (I == StubIndexes.end())
399  return nullptr;
400  auto Key = I->second.first;
401  void *StubAddr = IndirectStubsInfos[Key.first].getStub(Key.second);
402  assert(StubAddr && "Missing stub address");
403  auto StubTargetAddr =
404  static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(StubAddr));
405  auto StubSymbol = JITEvaluatedSymbol(StubTargetAddr, I->second.second);
406  if (ExportedStubsOnly && !StubSymbol.getFlags().isExported())
407  return nullptr;
408  return StubSymbol;
409  }
410 
412  std::lock_guard<std::mutex> Lock(StubsMutex);
413  auto I = StubIndexes.find(Name);
414  if (I == StubIndexes.end())
415  return nullptr;
416  auto Key = I->second.first;
417  void *PtrAddr = IndirectStubsInfos[Key.first].getPtr(Key.second);
418  assert(PtrAddr && "Missing pointer address");
419  auto PtrTargetAddr =
420  static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(PtrAddr));
421  return JITEvaluatedSymbol(PtrTargetAddr, I->second.second);
422  }
423 
425  using AtomicIntPtr = std::atomic<uintptr_t>;
426 
427  std::lock_guard<std::mutex> Lock(StubsMutex);
428  auto I = StubIndexes.find(Name);
429  assert(I != StubIndexes.end() && "No stub pointer for symbol");
430  auto Key = I->second.first;
431  AtomicIntPtr *AtomicStubPtr = reinterpret_cast<AtomicIntPtr *>(
432  IndirectStubsInfos[Key.first].getPtr(Key.second));
433  *AtomicStubPtr = static_cast<uintptr_t>(NewAddr);
434  return Error::success();
435  }
436 
437 private:
438  Error reserveStubs(unsigned NumStubs) {
439  if (NumStubs <= FreeStubs.size())
440  return Error::success();
441 
442  unsigned NewStubsRequired = NumStubs - FreeStubs.size();
443  unsigned NewBlockId = IndirectStubsInfos.size();
444  auto ISI =
445  LocalIndirectStubsInfo<TargetT>::create(NewStubsRequired, PageSize);
446  if (!ISI)
447  return ISI.takeError();
448  for (unsigned I = 0; I < ISI->getNumStubs(); ++I)
449  FreeStubs.push_back(std::make_pair(NewBlockId, I));
450  IndirectStubsInfos.push_back(std::move(*ISI));
451  return Error::success();
452  }
453 
454  void createStubInternal(StringRef StubName, JITTargetAddress InitAddr,
455  JITSymbolFlags StubFlags) {
456  auto Key = FreeStubs.back();
457  FreeStubs.pop_back();
458  *IndirectStubsInfos[Key.first].getPtr(Key.second) =
459  jitTargetAddressToPointer<void *>(InitAddr);
460  StubIndexes[StubName] = std::make_pair(Key, StubFlags);
461  }
462 
463  unsigned PageSize = sys::Process::getPageSizeEstimate();
464  std::mutex StubsMutex;
465  std::vector<LocalIndirectStubsInfo<TargetT>> IndirectStubsInfos;
466  using StubKey = std::pair<uint16_t, uint16_t>;
467  std::vector<StubKey> FreeStubs;
468  StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
469 };
470 
471 /// Create a local compile callback manager.
472 ///
473 /// The given target triple will determine the ABI, and the given
474 /// ErrorHandlerAddress will be used by the resulting compile callback
475 /// manager if a compile callback fails.
476 Expected<std::unique_ptr<JITCompileCallbackManager>>
477 createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES,
478  JITTargetAddress ErrorHandlerAddress);
479 
480 /// Create a local indriect stubs manager builder.
481 ///
482 /// The given target triple will determine the ABI.
483 std::function<std::unique_ptr<IndirectStubsManager>()>
485 
486 /// Build a function pointer of FunctionType with the given constant
487 /// address.
488 ///
489 /// Usage example: Turn a trampoline address into a function pointer constant
490 /// for use in a stub.
492 
493 /// Create a function pointer with the given type, name, and initializer
494 /// in the given Module.
495 GlobalVariable *createImplPointer(PointerType &PT, Module &M, const Twine &Name,
496  Constant *Initializer);
497 
498 /// Turn a function declaration into a stub function that makes an
499 /// indirect call using the given function pointer.
500 void makeStub(Function &F, Value &ImplPointer);
501 
502 /// Promotes private symbols to global hidden, and renames to prevent clashes
503 /// with other promoted symbols. The same SymbolPromoter instance should be
504 /// used for all symbols to be added to a single JITDylib.
506 public:
507  /// Promote symbols in the given module. Returns the set of global values
508  /// that have been renamed/promoted.
509  std::vector<GlobalValue *> operator()(Module &M);
510 
511 private:
512  unsigned NextId = 0;
513 };
514 
515 /// Clone a function declaration into a new module.
516 ///
517 /// This function can be used as the first step towards creating a callback
518 /// stub (see makeStub), or moving a function body (see moveFunctionBody).
519 ///
520 /// If the VMap argument is non-null, a mapping will be added between F and
521 /// the new declaration, and between each of F's arguments and the new
522 /// declaration's arguments. This map can then be passed in to moveFunction to
523 /// move the function body if required. Note: When moving functions between
524 /// modules with these utilities, all decls should be cloned (and added to a
525 /// single VMap) before any bodies are moved. This will ensure that references
526 /// between functions all refer to the versions in the new module.
528  ValueToValueMapTy *VMap = nullptr);
529 
530 /// Move the body of function 'F' to a cloned function declaration in a
531 /// different module (See related cloneFunctionDecl).
532 ///
533 /// If the target function declaration is not supplied via the NewF parameter
534 /// then it will be looked up via the VMap.
535 ///
536 /// This will delete the body of function 'F' from its original parent module,
537 /// but leave its declaration.
538 void moveFunctionBody(Function &OrigF, ValueToValueMapTy &VMap,
539  ValueMaterializer *Materializer = nullptr,
540  Function *NewF = nullptr);
541 
542 /// Clone a global variable declaration into a new module.
544  ValueToValueMapTy *VMap = nullptr);
545 
546 /// Move global variable GV from its parent module to cloned global
547 /// declaration in a different module.
548 ///
549 /// If the target global declaration is not supplied via the NewGV parameter
550 /// then it will be looked up via the VMap.
551 ///
552 /// This will delete the initializer of GV from its original parent module,
553 /// but leave its declaration.
555  ValueToValueMapTy &VMap,
556  ValueMaterializer *Materializer = nullptr,
557  GlobalVariable *NewGV = nullptr);
558 
559 /// Clone a global alias declaration into a new module.
561  ValueToValueMapTy &VMap);
562 
563 /// Clone module flags metadata into the destination module.
564 void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
565  ValueToValueMapTy &VMap);
566 
567 /// Introduce relocations to \p Sym in its own definition if there are any
568 /// pointers formed via PC-relative address that do not already have a
569 /// relocation.
570 ///
571 /// This is useful when introducing indirection via a stub function at link time
572 /// without compiler support. If a function pointer is formed without a
573 /// relocation, e.g. in the definition of \c foo
574 ///
575 /// \code
576 /// _foo:
577 /// leaq -7(%rip), rax # form pointer to _foo without relocation
578 /// _bar:
579 /// leaq (%rip), %rax # uses X86_64_RELOC_SIGNED to '_foo'
580 /// \endcode
581 ///
582 /// the pointer to \c _foo computed by \c _foo and \c _bar may differ if we
583 /// introduce a stub for _foo. If the pointer is used as a key, this may be
584 /// observable to the program. This pass will attempt to introduce the missing
585 /// "self-relocation" on the leaq instruction.
586 ///
587 /// This is based on disassembly and should be considered "best effort". It may
588 /// silently fail to add relocations.
591  MCDisassembler &Disassembler,
592  MCInstrAnalysis &MIA);
593 
594 } // end namespace orc
595 
596 } // end namespace llvm
597 
598 #endif // LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
llvm::orc::IndirectStubsManager::createStubs
virtual Error createStubs(const StubInitsMap &StubInits)=0
Create StubInits.size() stubs with the given names, target addresses, and flags.
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
PointerType
Definition: ItaniumDemangle.h:594
llvm::sys::Memory::MF_READ
@ MF_READ
Definition: Memory.h:55
llvm::orc::LocalIndirectStubsManager::updatePointer
Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override
Change the value of the implementation pointer for the stub.
Definition: IndirectionUtils.h:424
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::sys::Memory::MF_WRITE
@ MF_WRITE
Definition: Memory.h:56
llvm::orc::LocalIndirectStubsManager::createStub
Error createStub(StringRef StubName, JITTargetAddress StubAddr, JITSymbolFlags StubFlags) override
Create a single stub with the given name, target address and flags.
Definition: IndirectionUtils.h:372
llvm::orc::JITDylib
A symbol table that supports asynchoronous symbol queries.
Definition: Core.h:922
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
JITSymbol.h
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
ValueMapper.h
FunctionType
Definition: ItaniumDemangle.h:779
llvm::orc::LocalJITCompileCallbackManager
Manage compile callbacks for in-process JITs.
Definition: IndirectionUtils.h:241
llvm::unique_function
unique_function is a type-erasing functor similar to std::function.
Definition: FunctionExtras.h:56
llvm::orc::LocalTrampolinePool
A trampoline pool for trampolines within the current process.
Definition: IndirectionUtils.h:102
llvm::Function
Definition: Function.h:62
StringRef.h
llvm::orc::cloneModuleFlagsMetadata
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src, ValueToValueMapTy &VMap)
Clone module flags metadata into the destination module.
Definition: IndirectionUtils.cpp:371
llvm::orc::IndirectStubsManager
Base class for managing collections of named indirect stubs.
Definition: IndirectionUtils.h:282
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::orc::LocalIndirectStubsInfo
Definition: IndirectionUtils.h:312
llvm::GlobalAlias
Definition: GlobalAlias.h:28
llvm::sys::Memory::allocateMappedMemory
static MemoryBlock allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, unsigned Flags, std::error_code &EC)
This method allocates a block of memory that is suitable for loading dynamically generated code (e....
Error.h
llvm::orc::LocalJITCompileCallbackManager::Create
static Expected< std::unique_ptr< LocalJITCompileCallbackManager > > Create(ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress)
Create a new LocalJITCompileCallbackManager.
Definition: IndirectionUtils.h:245
llvm::orc::IndirectStubsManager::createStub
virtual Error createStub(StringRef StubName, JITTargetAddress StubAddr, JITSymbolFlags StubFlags)=0
Create a single stub with the given name, target address and flags.
llvm::orc::LocalIndirectStubsInfo::getStub
void * getStub(unsigned Idx) const
Definition: IndirectionUtils.h:352
llvm::sys::MemoryBlock
This class encapsulates the notion of a memory block which has an address and a size.
Definition: Memory.h:31
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
OrcABISupport.h
llvm::sys::OwningMemoryBlock::base
void * base() const
Definition: Memory.h:154
llvm::JITSymbolFlags
Flags for symbols in the JIT.
Definition: JITSymbol.h:74
llvm::orc::TrampolinePool::releaseTrampoline
void releaseTrampoline(JITTargetAddress TrampolineAddr)
Returns the given trampoline to the pool for re-use.
Definition: IndirectionUtils.h:89
llvm::JITEvaluatedSymbol
Represents a symbol that has been evaluated to an address already.
Definition: JITSymbol.h:229
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
llvm::orc::JITCompileCallbackManager::setTrampolinePool
void setTrampolinePool(std::unique_ptr< TrampolinePool > TP)
Definition: IndirectionUtils.h:225
Process.h
PageSize
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::orc::createIRTypedAddress
Constant * createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr)
Build a function pointer of FunctionType with the given constant address.
Definition: IndirectionUtils.cpp:225
llvm::orc::JITCompileCallbackManager
Target-independent base class for compile callback management.
Definition: IndirectionUtils.h:203
llvm::orc::LocalIndirectStubsManager::findStub
JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override
Find the stub with the given name.
Definition: IndirectionUtils.h:395
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:90
llvm::orc::SymbolLinkagePromoter::operator()
std::vector< GlobalValue * > operator()(Module &M)
Promote symbols in the given module.
Definition: IndirectionUtils.cpp:262
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::orc::cloneGlobalVariableDecl
GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
Definition: IndirectionUtils.cpp:330
llvm::orc::TrampolinePool::ResolveLandingFunction
unique_function< void(JITTargetAddress TrampolineAddr, NotifyLandingResolvedFunction OnLandingResolved) const > ResolveLandingFunction
Definition: IndirectionUtils.h:70
llvm::orc::TrampolinePool
Base class for pools of compiler re-entry trampolines.
Definition: IndirectionUtils.h:63
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:27
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition: Error.h:1099
StringMap.h
llvm::sys::OwningMemoryBlock
Owning version of MemoryBlock.
Definition: Memory.h:137
llvm::StringMap
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:108
llvm::orc::LocalIndirectStubsInfo::getPtr
void ** getPtr(unsigned Idx) const
Definition: IndirectionUtils.h:356
llvm::sys::Memory::MF_EXEC
@ MF_EXEC
Definition: Memory.h:57
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::orc::createLocalCompileCallbackManager
Expected< std::unique_ptr< JITCompileCallbackManager > > createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress)
Create a local compile callback manager.
Definition: IndirectionUtils.cpp:122
llvm::orc::TrampolinePool::AvailableTrampolines
std::vector< JITTargetAddress > AvailableTrampolines
Definition: IndirectionUtils.h:98
uint64_t
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::orc::createLocalIndirectStubsManagerBuilder
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
Definition: IndirectionUtils.cpp:169
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::MCDisassembler
Superclass for all disassemblers.
Definition: MCDisassembler.h:76
llvm::orc::IndirectStubsManager::updatePointer
virtual Error updatePointer(StringRef Name, JITTargetAddress NewAddr)=0
Change the value of the implementation pointer for the stub.
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::orc::LocalIndirectStubsManager::createStubs
Error createStubs(const StubInitsMap &StubInits) override
Create StubInits.size() stubs with the given names, target addresses, and flags.
Definition: IndirectionUtils.h:383
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:1639
llvm::codeview::CompileSym2Flags::EC
@ EC
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::orc::JITCompileCallbackManager::JITCompileCallbackManager
JITCompileCallbackManager(std::unique_ptr< TrampolinePool > TP, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress)
Construct a JITCompileCallbackManager.
Definition: IndirectionUtils.h:218
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::StringMapImpl::size
unsigned size() const
Definition: StringMap.h:93
llvm::orc::TrampolinePool::grow
virtual Error grow()=0
_
#define _
Definition: HexagonMCCodeEmitter.cpp:47
llvm::orc::createImplPointer
GlobalVariable * createImplPointer(PointerType &PT, Module &M, const Twine &Name, Constant *Initializer)
Create a function pointer with the given type, name, and initializer in the given Module.
Definition: IndirectionUtils.cpp:234
llvm::orc::cloneGlobalAliasDecl
GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new module.
Definition: IndirectionUtils.cpp:360
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::orc::cloneFunctionDecl
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
Definition: IndirectionUtils.cpp:292
llvm::orc::moveGlobalVariableInitializer
void moveGlobalVariableInitializer(GlobalVariable &OrigGV, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, GlobalVariable *NewGV=nullptr)
Move global variable GV from its parent module to cloned global declaration in a different module.
Definition: IndirectionUtils.cpp:342
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
Memory.h
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::pointerToJITTargetAddress
JITTargetAddress pointerToJITTargetAddress(T *Ptr)
Convert a pointer to a JITTargetAddress.
Definition: JITSymbol.h:69
llvm::orc::makeStub
void makeStub(Function &F, Value &ImplPointer)
Turn a function declaration into a stub function that makes an indirect call using the given function...
Definition: IndirectionUtils.cpp:243
llvm::orc::JITCompileCallbackManager::~JITCompileCallbackManager
virtual ~JITCompileCallbackManager()=default
llvm::orc::JITCompileCallbackManager::CompileFunction
std::function< JITTargetAddress()> CompileFunction
Definition: IndirectionUtils.h:205
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::orc::IndirectStubsManager::findPointer
virtual JITEvaluatedSymbol findPointer(StringRef Name)=0
Find the implementation-pointer for the stub.
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1271
llvm::orc::addFunctionPointerRelocationsToCurrentSymbol
Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym, jitlink::LinkGraph &G, MCDisassembler &Disassembler, MCInstrAnalysis &MIA)
Introduce relocations to Sym in its own definition if there are any pointers formed via PC-relative a...
Definition: IndirectionUtils.cpp:380
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::JITTargetAddress
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Definition: JITSymbol.h:42
llvm::sys::OwningMemoryBlock::getMemoryBlock
MemoryBlock getMemoryBlock() const
Definition: Memory.h:158
llvm::orc::LocalIndirectStubsManager
IndirectStubsManager implementation for the host architecture, e.g.
Definition: IndirectionUtils.h:370
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
Core.h
llvm::orc::LocalIndirectStubsInfo::LocalIndirectStubsInfo
LocalIndirectStubsInfo(unsigned NumStubs, sys::OwningMemoryBlock StubsMem)
Definition: IndirectionUtils.h:314
llvm::sys::Memory::protectMappedMemory
static std::error_code protectMappedMemory(const MemoryBlock &Block, unsigned Flags)
This method sets the protection flags for a block of memory to the state specified by /p Flags.
llvm::orc::JITCompileCallbackManager::executeCompileCallback
JITTargetAddress executeCompileCallback(JITTargetAddress TrampolineAddr)
Execute the callback for the given trampoline id.
Definition: IndirectionUtils.cpp:81
llvm::orc::TrampolinePool::TPMutex
std::mutex TPMutex
Definition: IndirectionUtils.h:97
llvm::orc::LocalTrampolinePool::Create
static Expected< std::unique_ptr< LocalTrampolinePool > > Create(ResolveLandingFunction ResolveLanding)
Creates a LocalTrampolinePool with the given RunCallback function.
Definition: IndirectionUtils.h:108
llvm::orc::TrampolinePool::NotifyLandingResolvedFunction
unique_function< void(JITTargetAddress) const > NotifyLandingResolvedFunction
Definition: IndirectionUtils.h:66
llvm::orc::LocalIndirectStubsInfo::getNumStubs
unsigned getNumStubs() const
Definition: IndirectionUtils.h:350
llvm::orc::IndirectStubsManager::~IndirectStubsManager
virtual ~IndirectStubsManager()=default
llvm::sys::Process::getPageSizeEstimate
static unsigned getPageSizeEstimate()
Get the process's estimated page size.
Definition: Process.h:62
llvm::orc::TrampolinePool::~TrampolinePool
virtual ~TrampolinePool()
Definition: IndirectionUtils.cpp:62
llvm::orc::JITCompileCallbackManager::getCompileCallback
Expected< JITTargetAddress > getCompileCallback(CompileFunction Compile)
Reserve a compile callback.
Definition: IndirectionUtils.cpp:66
llvm::orc::moveFunctionBody
void moveFunctionBody(Function &OrigF, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, Function *NewF=nullptr)
Move the body of function 'F' to a cloned function declaration in a different module (See related clo...
Definition: IndirectionUtils.cpp:310
llvm::ValueMaterializer
This is a class that can be implemented by clients to materialize Values on demand.
Definition: ValueMapper.h:49
llvm::orc::LocalIndirectStubsManager::findPointer
JITEvaluatedSymbol findPointer(StringRef Name) override
Find the implementation-pointer for the stub.
Definition: IndirectionUtils.h:411
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::orc::IndirectStubsManager::findStub
virtual JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly)=0
Find the stub with the given name.
llvm::orc::TrampolinePool::getTrampoline
Expected< JITTargetAddress > getTrampoline()
Get an available trampoline address.
Definition: IndirectionUtils.h:76
llvm::orc::SymbolLinkagePromoter
Promotes private symbols to global hidden, and renames to prevent clashes with other promoted symbols...
Definition: IndirectionUtils.h:505
llvm::orc::LocalIndirectStubsInfo::create
static Expected< LocalIndirectStubsInfo > create(unsigned MinStubs, unsigned PageSize)
Definition: IndirectionUtils.h:317