Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:52

0001 //===- EPCGenericJITLinkMemoryManager.h - EPC-based mem manager -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Implements JITLinkMemoryManager by making remove calls via
0010 // ExecutorProcessControl::callWrapperAsync.
0011 //
0012 // This simplifies the implementaton of new ExecutorProcessControl instances,
0013 // as this implementation will always work (at the cost of some performance
0014 // overhead for the calls).
0015 //
0016 //===----------------------------------------------------------------------===//
0017 
0018 #ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICJITLINKMEMORYMANAGER_H
0019 #define LLVM_EXECUTIONENGINE_ORC_EPCGENERICJITLINKMEMORYMANAGER_H
0020 
0021 #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
0022 #include "llvm/ExecutionEngine/Orc/Core.h"
0023 
0024 namespace llvm {
0025 namespace orc {
0026 
0027 class EPCGenericJITLinkMemoryManager : public jitlink::JITLinkMemoryManager {
0028 public:
0029   /// Function addresses for memory access.
0030   struct SymbolAddrs {
0031     ExecutorAddr Allocator;
0032     ExecutorAddr Reserve;
0033     ExecutorAddr Finalize;
0034     ExecutorAddr Deallocate;
0035   };
0036 
0037   /// Create an EPCGenericJITLinkMemoryManager instance from a given set of
0038   /// function addrs.
0039   EPCGenericJITLinkMemoryManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
0040       : EPC(EPC), SAs(SAs) {}
0041 
0042   void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G,
0043                 OnAllocatedFunction OnAllocated) override;
0044 
0045   // Use overloads from base class.
0046   using JITLinkMemoryManager::allocate;
0047 
0048   void deallocate(std::vector<FinalizedAlloc> Allocs,
0049                   OnDeallocatedFunction OnDeallocated) override;
0050 
0051   // Use overloads from base class.
0052   using JITLinkMemoryManager::deallocate;
0053 
0054 private:
0055   class InFlightAlloc;
0056 
0057   void completeAllocation(ExecutorAddr AllocAddr, jitlink::BasicLayout BL,
0058                           OnAllocatedFunction OnAllocated);
0059 
0060   ExecutorProcessControl &EPC;
0061   SymbolAddrs SAs;
0062 };
0063 
0064 namespace shared {
0065 
0066 /// FIXME: This specialization should be moved into TargetProcessControlTypes.h
0067 ///        (or wherever those types get merged to) once ORC depends on JITLink.
0068 template <>
0069 class SPSSerializationTraits<SPSExecutorAddr,
0070                              jitlink::JITLinkMemoryManager::FinalizedAlloc> {
0071 public:
0072   static size_t size(const jitlink::JITLinkMemoryManager::FinalizedAlloc &FA) {
0073     return SPSArgList<SPSExecutorAddr>::size(ExecutorAddr(FA.getAddress()));
0074   }
0075 
0076   static bool
0077   serialize(SPSOutputBuffer &OB,
0078             const jitlink::JITLinkMemoryManager::FinalizedAlloc &FA) {
0079     return SPSArgList<SPSExecutorAddr>::serialize(
0080         OB, ExecutorAddr(FA.getAddress()));
0081   }
0082 
0083   static bool deserialize(SPSInputBuffer &IB,
0084                           jitlink::JITLinkMemoryManager::FinalizedAlloc &FA) {
0085     ExecutorAddr A;
0086     if (!SPSArgList<SPSExecutorAddr>::deserialize(IB, A))
0087       return false;
0088     FA = jitlink::JITLinkMemoryManager::FinalizedAlloc(A);
0089     return true;
0090   }
0091 };
0092 
0093 } // end namespace shared
0094 } // end namespace orc
0095 } // end namespace llvm
0096 
0097 #endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICJITLINKMEMORYMANAGER_H