EPCGenericJITLinkMemoryManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- EPCGenericJITLinkMemoryManager.h - EPC-based mem manager -*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Implements JITLinkMemoryManager by making remove calls via
  15. // ExecutorProcessControl::callWrapperAsync.
  16. //
  17. // This simplifies the implementaton of new ExecutorProcessControl instances,
  18. // as this implementation will always work (at the cost of some performance
  19. // overhead for the calls).
  20. //
  21. //===----------------------------------------------------------------------===//
  22. #ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICJITLINKMEMORYMANAGER_H
  23. #define LLVM_EXECUTIONENGINE_ORC_EPCGENERICJITLINKMEMORYMANAGER_H
  24. #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
  25. #include "llvm/ExecutionEngine/Orc/Core.h"
  26. namespace llvm {
  27. namespace orc {
  28. class EPCGenericJITLinkMemoryManager : public jitlink::JITLinkMemoryManager {
  29. public:
  30. /// Function addresses for memory access.
  31. struct SymbolAddrs {
  32. ExecutorAddr Allocator;
  33. ExecutorAddr Reserve;
  34. ExecutorAddr Finalize;
  35. ExecutorAddr Deallocate;
  36. };
  37. /// Create an EPCGenericJITLinkMemoryManager instance from a given set of
  38. /// function addrs.
  39. EPCGenericJITLinkMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
  40. : EPC(EPC), SAs(SAs) {}
  41. void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G,
  42. OnAllocatedFunction OnAllocated) override;
  43. // Use overloads from base class.
  44. using JITLinkMemoryManager::allocate;
  45. void deallocate(std::vector<FinalizedAlloc> Allocs,
  46. OnDeallocatedFunction OnDeallocated) override;
  47. // Use overloads from base class.
  48. using JITLinkMemoryManager::deallocate;
  49. private:
  50. class InFlightAlloc;
  51. void completeAllocation(ExecutorAddr AllocAddr, jitlink::BasicLayout BL,
  52. OnAllocatedFunction OnAllocated);
  53. ExecutorProcessControl &EPC;
  54. SymbolAddrs SAs;
  55. };
  56. namespace shared {
  57. /// FIXME: This specialization should be moved into TargetProcessControlTypes.h
  58. /// (or whereever those types get merged to) once ORC depends on JITLink.
  59. template <>
  60. class SPSSerializationTraits<SPSExecutorAddr,
  61. jitlink::JITLinkMemoryManager::FinalizedAlloc> {
  62. public:
  63. static size_t size(const jitlink::JITLinkMemoryManager::FinalizedAlloc &FA) {
  64. return SPSArgList<SPSExecutorAddr>::size(ExecutorAddr(FA.getAddress()));
  65. }
  66. static bool
  67. serialize(SPSOutputBuffer &OB,
  68. const jitlink::JITLinkMemoryManager::FinalizedAlloc &FA) {
  69. return SPSArgList<SPSExecutorAddr>::serialize(
  70. OB, ExecutorAddr(FA.getAddress()));
  71. }
  72. static bool deserialize(SPSInputBuffer &IB,
  73. jitlink::JITLinkMemoryManager::FinalizedAlloc &FA) {
  74. ExecutorAddr A;
  75. if (!SPSArgList<SPSExecutorAddr>::deserialize(IB, A))
  76. return false;
  77. FA = jitlink::JITLinkMemoryManager::FinalizedAlloc(A);
  78. return true;
  79. }
  80. };
  81. } // end namespace shared
  82. } // end namespace orc
  83. } // end namespace llvm
  84. #endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICJITLINKMEMORYMANAGER_H
  85. #ifdef __GNUC__
  86. #pragma GCC diagnostic pop
  87. #endif