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 
49 namespace orc {
50 
51 /// Base class for pools of compiler re-entry trampolines.
52 /// These trampolines are callable addresses that save all register state
53 /// before calling a supplied function to return the trampoline landing
54 /// address, then restore all state before jumping to that address. They
55 /// are used by various ORC APIs to support lazy compilation
57 public:
60 
62  JITTargetAddress TrampolineAddr,
63  NotifyLandingResolvedFunction OnLandingResolved) const>;
64 
65  virtual ~TrampolinePool();
66 
67  /// Get an available trampoline address.
68  /// Returns an error if no trampoline can be created.
70  std::lock_guard<std::mutex> Lock(TPMutex);
71  if (AvailableTrampolines.empty()) {
72  if (auto Err = grow())
73  return std::move(Err);
74  }
75  assert(!AvailableTrampolines.empty() && "Failed to grow trampoline pool");
76  auto TrampolineAddr = AvailableTrampolines.back();
77  AvailableTrampolines.pop_back();
78  return TrampolineAddr;
79  }
80 
81  /// Returns the given trampoline to the pool for re-use.
82  void releaseTrampoline(JITTargetAddress TrampolineAddr) {
83  std::lock_guard<std::mutex> Lock(TPMutex);
84  AvailableTrampolines.push_back(TrampolineAddr);
85  }
86 
87 protected:
88  virtual Error grow() = 0;
89 
90  std::mutex TPMutex;
91  std::vector<JITTargetAddress> AvailableTrampolines;
92 };
93 
94 /// A trampoline pool for trampolines within the current process.
95 template <typename ORCABI> class LocalTrampolinePool : public TrampolinePool {
96 public:
97  /// Creates a LocalTrampolinePool with the given RunCallback function.
98  /// Returns an error if this function is unable to correctly allocate, write
99  /// and protect the resolver code block.
101  Create(ResolveLandingFunction ResolveLanding) {
102  Error Err = Error::success();
103 
104  auto LTP = std::unique_ptr<LocalTrampolinePool>(
105  new LocalTrampolinePool(std::move(ResolveLanding), Err));
106 
107  if (Err)
108  return std::move(Err);
109  return std::move(LTP);
110  }
111 
112 private:
113  static JITTargetAddress reenter(void *TrampolinePoolPtr, void *TrampolineId) {
115  static_cast<LocalTrampolinePool *>(TrampolinePoolPtr);
116 
117  std::promise<JITTargetAddress> LandingAddressP;
118  auto LandingAddressF = LandingAddressP.get_future();
119 
120  TrampolinePool->ResolveLanding(pointerToJITTargetAddress(TrampolineId),
121  [&](JITTargetAddress LandingAddress) {
122  LandingAddressP.set_value(LandingAddress);
123  });
124  return LandingAddressF.get();
125  }
126 
127  LocalTrampolinePool(ResolveLandingFunction ResolveLanding, Error &Err)
128  : ResolveLanding(std::move(ResolveLanding)) {
129 
130  ErrorAsOutParameter _(&Err);
131 
132  /// Try to set up the resolver block.
133  std::error_code EC;
134  ResolverBlock = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
135  ORCABI::ResolverCodeSize, nullptr,
137  if (EC) {
138  Err = errorCodeToError(EC);
139  return;
140  }
141 
142  ORCABI::writeResolverCode(static_cast<char *>(ResolverBlock.base()),
143  pointerToJITTargetAddress(ResolverBlock.base()),
144  pointerToJITTargetAddress(&reenter),
146 
150  if (EC) {
151  Err = errorCodeToError(EC);
152  return;
153  }
154  }
155 
156  Error grow() override {
157  assert(AvailableTrampolines.empty() && "Growing prematurely?");
158 
159  std::error_code EC;
160  auto TrampolineBlock =
161  sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
164  if (EC)
165  return errorCodeToError(EC);
166 
167  unsigned NumTrampolines =
169  ORCABI::TrampolineSize;
170 
171  char *TrampolineMem = static_cast<char *>(TrampolineBlock.base());
172  ORCABI::writeTrampolines(
173  TrampolineMem, pointerToJITTargetAddress(TrampolineMem),
174  pointerToJITTargetAddress(ResolverBlock.base()), NumTrampolines);
175 
176  for (unsigned I = 0; I < NumTrampolines; ++I)
178  TrampolineMem + (I * ORCABI::TrampolineSize)));
179 
180  if (auto EC = sys::Memory::protectMappedMemory(
181  TrampolineBlock.getMemoryBlock(),
183  return errorCodeToError(EC);
184 
185  TrampolineBlocks.push_back(std::move(TrampolineBlock));
186  return Error::success();
187  }
188 
189  ResolveLandingFunction ResolveLanding;
190 
191  sys::OwningMemoryBlock ResolverBlock;
192  std::vector<sys::OwningMemoryBlock> TrampolineBlocks;
193 };
194 
195 /// Target-independent base class for compile callback management.
197 public:
199 
200  virtual ~JITCompileCallbackManager() = default;
201 
202  /// Reserve a compile callback.
204 
205  /// Execute the callback for the given trampoline id. Called by the JIT
206  /// to compile functions on demand.
208 
209 protected:
210  /// Construct a JITCompileCallbackManager.
211  JITCompileCallbackManager(std::unique_ptr<TrampolinePool> TP,
212  ExecutionSession &ES,
213  JITTargetAddress ErrorHandlerAddress)
214  : TP(std::move(TP)), ES(ES),
215  CallbacksJD(ES.createBareJITDylib("<Callbacks>")),
216  ErrorHandlerAddress(ErrorHandlerAddress) {}
217 
218  void setTrampolinePool(std::unique_ptr<TrampolinePool> TP) {
219  this->TP = std::move(TP);
220  }
221 
222 private:
223  std::mutex CCMgrMutex;
224  std::unique_ptr<TrampolinePool> TP;
225  ExecutionSession &ES;
226  JITDylib &CallbacksJD;
227  JITTargetAddress ErrorHandlerAddress;
228  std::map<JITTargetAddress, SymbolStringPtr> AddrToSymbol;
229  size_t NextCallbackId = 0;
230 };
231 
232 /// Manage compile callbacks for in-process JITs.
233 template <typename ORCABI>
235 public:
236  /// Create a new LocalJITCompileCallbackManager.
238  Create(ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress) {
239  Error Err = Error::success();
240  auto CCMgr = std::unique_ptr<LocalJITCompileCallbackManager>(
241  new LocalJITCompileCallbackManager(ES, ErrorHandlerAddress, Err));
242  if (Err)
243  return std::move(Err);
244  return std::move(CCMgr);
245  }
246 
247 private:
248  /// Construct a InProcessJITCompileCallbackManager.
249  /// @param ErrorHandlerAddress The address of an error handler in the target
250  /// process to be used if a compile callback fails.
252  JITTargetAddress ErrorHandlerAddress,
253  Error &Err)
254  : JITCompileCallbackManager(nullptr, ES, ErrorHandlerAddress) {
255  using NotifyLandingResolvedFunction =
257 
258  ErrorAsOutParameter _(&Err);
260  [this](JITTargetAddress TrampolineAddr,
261  NotifyLandingResolvedFunction NotifyLandingResolved) {
262  NotifyLandingResolved(executeCompileCallback(TrampolineAddr));
263  });
264 
265  if (!TP) {
266  Err = TP.takeError();
267  return;
268  }
269 
271  }
272 };
273 
274 /// Base class for managing collections of named indirect stubs.
276 public:
277  /// Map type for initializing the manager. See init.
279 
280  virtual ~IndirectStubsManager() = default;
281 
282  /// Create a single stub with the given name, target address and flags.
283  virtual Error createStub(StringRef StubName, JITTargetAddress StubAddr,
284  JITSymbolFlags StubFlags) = 0;
285 
286  /// Create StubInits.size() stubs with the given names, target
287  /// addresses, and flags.
288  virtual Error createStubs(const StubInitsMap &StubInits) = 0;
289 
290  /// Find the stub with the given name. If ExportedStubsOnly is true,
291  /// this will only return a result if the stub's flags indicate that it
292  /// is exported.
293  virtual JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) = 0;
294 
295  /// Find the implementation-pointer for the stub.
297 
298  /// Change the value of the implementation pointer for the stub.
299  virtual Error updatePointer(StringRef Name, JITTargetAddress NewAddr) = 0;
300 
301 private:
302  virtual void anchor();
303 };
304 
305 template <typename ORCABI> class LocalIndirectStubsInfo {
306 public:
307  LocalIndirectStubsInfo(unsigned NumStubs, sys::OwningMemoryBlock StubsMem)
308  : NumStubs(NumStubs), StubsMem(std::move(StubsMem)) {}
309 
310  static Expected<LocalIndirectStubsInfo> create(unsigned MinStubs,
311  unsigned PageSize) {
312  auto ISAS = getIndirectStubsBlockSizes<ORCABI>(MinStubs, PageSize);
313 
314  assert((ISAS.StubBytes % PageSize == 0) &&
315  "StubBytes is not a page size multiple");
316  uint64_t PointerAlloc = alignTo(ISAS.PointerBytes, PageSize);
317 
318  // Allocate memory for stubs and pointers in one call.
319  std::error_code EC;
320  auto StubsAndPtrsMem =
322  ISAS.StubBytes + PointerAlloc, nullptr,
324  if (EC)
325  return errorCodeToError(EC);
326 
327  sys::MemoryBlock StubsBlock(StubsAndPtrsMem.base(), ISAS.StubBytes);
328  auto StubsBlockMem = static_cast<char *>(StubsAndPtrsMem.base());
329  auto PtrBlockAddress =
330  pointerToJITTargetAddress(StubsBlockMem) + ISAS.StubBytes;
331 
332  ORCABI::writeIndirectStubsBlock(StubsBlockMem,
333  pointerToJITTargetAddress(StubsBlockMem),
334  PtrBlockAddress, ISAS.NumStubs);
335 
336  if (auto EC = sys::Memory::protectMappedMemory(
338  return errorCodeToError(EC);
339 
340  return LocalIndirectStubsInfo(ISAS.NumStubs, std::move(StubsAndPtrsMem));
341  }
342 
343  unsigned getNumStubs() const { return NumStubs; }
344 
345  void *getStub(unsigned Idx) const {
346  return static_cast<char *>(StubsMem.base()) + Idx * ORCABI::StubSize;
347  }
348 
349  void **getPtr(unsigned Idx) const {
350  char *PtrsBase =
351  static_cast<char *>(StubsMem.base()) + NumStubs * ORCABI::StubSize;
352  return reinterpret_cast<void **>(PtrsBase) + Idx;
353  }
354 
355 private:
356  unsigned NumStubs = 0;
357  sys::OwningMemoryBlock StubsMem;
358 };
359 
360 /// IndirectStubsManager implementation for the host architecture, e.g.
361 /// OrcX86_64. (See OrcArchitectureSupport.h).
362 template <typename TargetT>
364 public:
366  JITSymbolFlags StubFlags) override {
367  std::lock_guard<std::mutex> Lock(StubsMutex);
368  if (auto Err = reserveStubs(1))
369  return Err;
370 
371  createStubInternal(StubName, StubAddr, StubFlags);
372 
373  return Error::success();
374  }
375 
376  Error createStubs(const StubInitsMap &StubInits) override {
377  std::lock_guard<std::mutex> Lock(StubsMutex);
378  if (auto Err = reserveStubs(StubInits.size()))
379  return Err;
380 
381  for (auto &Entry : StubInits)
382  createStubInternal(Entry.first(), Entry.second.first,
383  Entry.second.second);
384 
385  return Error::success();
386  }
387 
388  JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
389  std::lock_guard<std::mutex> Lock(StubsMutex);
390  auto I = StubIndexes.find(Name);
391  if (I == StubIndexes.end())
392  return nullptr;
393  auto Key = I->second.first;
394  void *StubAddr = IndirectStubsInfos[Key.first].getStub(Key.second);
395  assert(StubAddr && "Missing stub address");
396  auto StubTargetAddr =
397  static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(StubAddr));
398  auto StubSymbol = JITEvaluatedSymbol(StubTargetAddr, I->second.second);
399  if (ExportedStubsOnly && !StubSymbol.getFlags().isExported())
400  return nullptr;
401  return StubSymbol;
402  }
403 
405  std::lock_guard<std::mutex> Lock(StubsMutex);
406  auto I = StubIndexes.find(Name);
407  if (I == StubIndexes.end())
408  return nullptr;
409  auto Key = I->second.first;
410  void *PtrAddr = IndirectStubsInfos[Key.first].getPtr(Key.second);
411  assert(PtrAddr && "Missing pointer address");
412  auto PtrTargetAddr =
413  static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(PtrAddr));
414  return JITEvaluatedSymbol(PtrTargetAddr, I->second.second);
415  }
416 
418  using AtomicIntPtr = std::atomic<uintptr_t>;
419 
420  std::lock_guard<std::mutex> Lock(StubsMutex);
421  auto I = StubIndexes.find(Name);
422  assert(I != StubIndexes.end() && "No stub pointer for symbol");
423  auto Key = I->second.first;
424  AtomicIntPtr *AtomicStubPtr = reinterpret_cast<AtomicIntPtr *>(
425  IndirectStubsInfos[Key.first].getPtr(Key.second));
426  *AtomicStubPtr = static_cast<uintptr_t>(NewAddr);
427  return Error::success();
428  }
429 
430 private:
431  Error reserveStubs(unsigned NumStubs) {
432  if (NumStubs <= FreeStubs.size())
433  return Error::success();
434 
435  unsigned NewStubsRequired = NumStubs - FreeStubs.size();
436  unsigned NewBlockId = IndirectStubsInfos.size();
437  auto ISI =
438  LocalIndirectStubsInfo<TargetT>::create(NewStubsRequired, PageSize);
439  if (!ISI)
440  return ISI.takeError();
441  for (unsigned I = 0; I < ISI->getNumStubs(); ++I)
442  FreeStubs.push_back(std::make_pair(NewBlockId, I));
443  IndirectStubsInfos.push_back(std::move(*ISI));
444  return Error::success();
445  }
446 
447  void createStubInternal(StringRef StubName, JITTargetAddress InitAddr,
448  JITSymbolFlags StubFlags) {
449  auto Key = FreeStubs.back();
450  FreeStubs.pop_back();
451  *IndirectStubsInfos[Key.first].getPtr(Key.second) =
452  jitTargetAddressToPointer<void *>(InitAddr);
453  StubIndexes[StubName] = std::make_pair(Key, StubFlags);
454  }
455 
456  unsigned PageSize = sys::Process::getPageSizeEstimate();
457  std::mutex StubsMutex;
458  std::vector<LocalIndirectStubsInfo<TargetT>> IndirectStubsInfos;
459  using StubKey = std::pair<uint16_t, uint16_t>;
460  std::vector<StubKey> FreeStubs;
461  StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
462 };
463 
464 /// Create a local compile callback manager.
465 ///
466 /// The given target triple will determine the ABI, and the given
467 /// ErrorHandlerAddress will be used by the resulting compile callback
468 /// manager if a compile callback fails.
469 Expected<std::unique_ptr<JITCompileCallbackManager>>
470 createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES,
471  JITTargetAddress ErrorHandlerAddress);
472 
473 /// Create a local indriect stubs manager builder.
474 ///
475 /// The given target triple will determine the ABI.
476 std::function<std::unique_ptr<IndirectStubsManager>()>
478 
479 /// Build a function pointer of FunctionType with the given constant
480 /// address.
481 ///
482 /// Usage example: Turn a trampoline address into a function pointer constant
483 /// for use in a stub.
485 
486 /// Create a function pointer with the given type, name, and initializer
487 /// in the given Module.
488 GlobalVariable *createImplPointer(PointerType &PT, Module &M, const Twine &Name,
489  Constant *Initializer);
490 
491 /// Turn a function declaration into a stub function that makes an
492 /// indirect call using the given function pointer.
493 void makeStub(Function &F, Value &ImplPointer);
494 
495 /// Promotes private symbols to global hidden, and renames to prevent clashes
496 /// with other promoted symbols. The same SymbolPromoter instance should be
497 /// used for all symbols to be added to a single JITDylib.
499 public:
500  /// Promote symbols in the given module. Returns the set of global values
501  /// that have been renamed/promoted.
502  std::vector<GlobalValue *> operator()(Module &M);
503 
504 private:
505  unsigned NextId = 0;
506 };
507 
508 /// Clone a function declaration into a new module.
509 ///
510 /// This function can be used as the first step towards creating a callback
511 /// stub (see makeStub), or moving a function body (see moveFunctionBody).
512 ///
513 /// If the VMap argument is non-null, a mapping will be added between F and
514 /// the new declaration, and between each of F's arguments and the new
515 /// declaration's arguments. This map can then be passed in to moveFunction to
516 /// move the function body if required. Note: When moving functions between
517 /// modules with these utilities, all decls should be cloned (and added to a
518 /// single VMap) before any bodies are moved. This will ensure that references
519 /// between functions all refer to the versions in the new module.
521  ValueToValueMapTy *VMap = nullptr);
522 
523 /// Move the body of function 'F' to a cloned function declaration in a
524 /// different module (See related cloneFunctionDecl).
525 ///
526 /// If the target function declaration is not supplied via the NewF parameter
527 /// then it will be looked up via the VMap.
528 ///
529 /// This will delete the body of function 'F' from its original parent module,
530 /// but leave its declaration.
531 void moveFunctionBody(Function &OrigF, ValueToValueMapTy &VMap,
532  ValueMaterializer *Materializer = nullptr,
533  Function *NewF = nullptr);
534 
535 /// Clone a global variable declaration into a new module.
537  ValueToValueMapTy *VMap = nullptr);
538 
539 /// Move global variable GV from its parent module to cloned global
540 /// declaration in a different module.
541 ///
542 /// If the target global declaration is not supplied via the NewGV parameter
543 /// then it will be looked up via the VMap.
544 ///
545 /// This will delete the initializer of GV from its original parent module,
546 /// but leave its declaration.
548  ValueToValueMapTy &VMap,
549  ValueMaterializer *Materializer = nullptr,
550  GlobalVariable *NewGV = nullptr);
551 
552 /// Clone a global alias declaration into a new module.
554  ValueToValueMapTy &VMap);
555 
556 /// Clone module flags metadata into the destination module.
557 void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
558  ValueToValueMapTy &VMap);
559 
560 } // end namespace orc
561 
562 } // end namespace llvm
563 
564 #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:598
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:417
llvm
---------------------— PointerInfo ------------------------------------—
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:365
llvm::orc::JITDylib
A symbol table that supports asynchoronous symbol queries.
Definition: Core.h:907
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:783
llvm::orc::LocalJITCompileCallbackManager
Manage compile callbacks for in-process JITs.
Definition: IndirectionUtils.h:234
llvm::unique_function
unique_function is a type-erasing functor similar to std::function.
Definition: FunctionExtras.h:55
llvm::orc::LocalTrampolinePool
A trampoline pool for trampolines within the current process.
Definition: IndirectionUtils.h:95
llvm::Function
Definition: Function.h:61
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:366
llvm::orc::IndirectStubsManager
Base class for managing collections of named indirect stubs.
Definition: IndirectionUtils.h:275
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:305
llvm::GlobalAlias
Definition: GlobalAlias.h:27
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:238
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:345
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:153
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:82
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:218
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:220
llvm::orc::JITCompileCallbackManager
Target-independent base class for compile callback management.
Definition: IndirectionUtils.h:196
llvm::orc::LocalIndirectStubsManager::findStub
JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override
Find the stub with the given name.
Definition: IndirectionUtils.h:388
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
llvm::orc::SymbolLinkagePromoter::operator()
std::vector< GlobalValue * > operator()(Module &M)
Promote symbols in the given module.
Definition: IndirectionUtils.cpp:257
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:325
llvm::orc::TrampolinePool::ResolveLandingFunction
unique_function< void(JITTargetAddress TrampolineAddr, NotifyLandingResolvedFunction OnLandingResolved) const > ResolveLandingFunction
Definition: IndirectionUtils.h:63
llvm::orc::TrampolinePool
Base class for pools of compiler re-entry trampolines.
Definition: IndirectionUtils.h:56
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition: Error.h:1089
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:349
llvm::sys::Memory::MF_EXEC
@ MF_EXEC
Definition: Memory.h:57
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:117
llvm::orc::TrampolinePool::AvailableTrampolines
std::vector< JITTargetAddress > AvailableTrampolines
Definition: IndirectionUtils.h:91
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:164
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::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:376
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:1609
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:211
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:229
llvm::orc::cloneGlobalAliasDecl
GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new module.
Definition: IndirectionUtils.cpp:355
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::orc::cloneFunctionDecl
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
Definition: IndirectionUtils.cpp:287
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:337
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:238
llvm::orc::JITCompileCallbackManager::~JITCompileCallbackManager
virtual ~JITCompileCallbackManager()=default
llvm::orc::JITCompileCallbackManager::CompileFunction
std::function< JITTargetAddress()> CompileFunction
Definition: IndirectionUtils.h:198
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:1275
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:157
llvm::orc::LocalIndirectStubsManager
IndirectStubsManager implementation for the host architecture, e.g.
Definition: IndirectionUtils.h:363
Core.h
llvm::orc::LocalIndirectStubsInfo::LocalIndirectStubsInfo
LocalIndirectStubsInfo(unsigned NumStubs, sys::OwningMemoryBlock StubsMem)
Definition: IndirectionUtils.h:307
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:76
llvm::orc::TrampolinePool::TPMutex
std::mutex TPMutex
Definition: IndirectionUtils.h:90
llvm::orc::LocalTrampolinePool::Create
static Expected< std::unique_ptr< LocalTrampolinePool > > Create(ResolveLandingFunction ResolveLanding)
Creates a LocalTrampolinePool with the given RunCallback function.
Definition: IndirectionUtils.h:101
llvm::orc::TrampolinePool::NotifyLandingResolvedFunction
unique_function< void(JITTargetAddress) const > NotifyLandingResolvedFunction
Definition: IndirectionUtils.h:59
llvm::orc::LocalIndirectStubsInfo::getNumStubs
unsigned getNumStubs() const
Definition: IndirectionUtils.h:343
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:57
llvm::orc::JITCompileCallbackManager::getCompileCallback
Expected< JITTargetAddress > getCompileCallback(CompileFunction Compile)
Reserve a compile callback.
Definition: IndirectionUtils.cpp:61
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:305
llvm::ValueMaterializer
This is a class that can be implemented by clients to materialize Values on demand.
Definition: ValueMapper.h:50
llvm::orc::LocalIndirectStubsManager::findPointer
JITEvaluatedSymbol findPointer(StringRef Name) override
Find the implementation-pointer for the stub.
Definition: IndirectionUtils.h:404
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:69
llvm::orc::SymbolLinkagePromoter
Promotes private symbols to global hidden, and renames to prevent clashes with other promoted symbols...
Definition: IndirectionUtils.h:498
llvm::orc::LocalIndirectStubsInfo::create
static Expected< LocalIndirectStubsInfo > create(unsigned MinStubs, unsigned PageSize)
Definition: IndirectionUtils.h:310