Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--------------- MapperJITLinkMemoryManager.h -*- 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 using MemoryMapper
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
0014 #define LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
0015 
0016 #include "llvm/ADT/IntervalMap.h"
0017 #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
0018 #include "llvm/ExecutionEngine/Orc/MemoryMapper.h"
0019 
0020 namespace llvm {
0021 namespace orc {
0022 
0023 class MapperJITLinkMemoryManager : public jitlink::JITLinkMemoryManager {
0024 public:
0025   MapperJITLinkMemoryManager(size_t ReservationGranularity,
0026                              std::unique_ptr<MemoryMapper> Mapper);
0027 
0028   template <class MemoryMapperType, class... Args>
0029   static Expected<std::unique_ptr<MapperJITLinkMemoryManager>>
0030   CreateWithMapper(size_t ReservationGranularity, Args &&...A) {
0031     auto Mapper = MemoryMapperType::Create(std::forward<Args>(A)...);
0032     if (!Mapper)
0033       return Mapper.takeError();
0034 
0035     return std::make_unique<MapperJITLinkMemoryManager>(ReservationGranularity,
0036                                                         std::move(*Mapper));
0037   }
0038 
0039   void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G,
0040                 OnAllocatedFunction OnAllocated) override;
0041   // synchronous overload
0042   using JITLinkMemoryManager::allocate;
0043 
0044   void deallocate(std::vector<FinalizedAlloc> Allocs,
0045                   OnDeallocatedFunction OnDeallocated) override;
0046   // synchronous overload
0047   using JITLinkMemoryManager::deallocate;
0048 
0049 private:
0050   class InFlightAlloc;
0051 
0052   std::mutex Mutex;
0053 
0054   // We reserve multiples of this from the executor address space
0055   size_t ReservationUnits;
0056 
0057   // Ranges that have been reserved in executor but not yet allocated
0058   using AvailableMemoryMap = IntervalMap<ExecutorAddr, bool>;
0059   AvailableMemoryMap::Allocator AMAllocator;
0060   IntervalMap<ExecutorAddr, bool> AvailableMemory;
0061 
0062   // Ranges that have been reserved in executor and already allocated
0063   DenseMap<ExecutorAddr, ExecutorAddrDiff> UsedMemory;
0064 
0065   std::unique_ptr<MemoryMapper> Mapper;
0066 };
0067 
0068 } // end namespace orc
0069 } // end namespace llvm
0070 
0071 #endif // LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H