File indexing completed on 2026-05-10 08:43:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
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
0042 using JITLinkMemoryManager::allocate;
0043
0044 void deallocate(std::vector<FinalizedAlloc> Allocs,
0045 OnDeallocatedFunction OnDeallocated) override;
0046
0047 using JITLinkMemoryManager::deallocate;
0048
0049 private:
0050 class InFlightAlloc;
0051
0052 std::mutex Mutex;
0053
0054
0055 size_t ReservationUnits;
0056
0057
0058 using AvailableMemoryMap = IntervalMap<ExecutorAddr, bool>;
0059 AvailableMemoryMap::Allocator AMAllocator;
0060 IntervalMap<ExecutorAddr, bool> AvailableMemory;
0061
0062
0063 DenseMap<ExecutorAddr, ExecutorAddrDiff> UsedMemory;
0064
0065 std::unique_ptr<MemoryMapper> Mapper;
0066 };
0067
0068 }
0069 }
0070
0071 #endif