blob: 40eef20a68a2fa227d8867584d40ea133bff374d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===--------------- MapperJITLinkMemoryManager.h -*- C++ -*---------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Implements JITLinkMemoryManager using MemoryMapper
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
#define LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/MemoryMapper.h"
namespace llvm {
namespace orc {
class MapperJITLinkMemoryManager : public jitlink::JITLinkMemoryManager {
public:
MapperJITLinkMemoryManager(size_t ReservationGranularity,
std::unique_ptr<MemoryMapper> Mapper);
template <class MemoryMapperType, class... Args>
static Expected<std::unique_ptr<MapperJITLinkMemoryManager>>
CreateWithMapper(size_t ReservationGranularity, Args &&...A) {
auto Mapper = MemoryMapperType::Create(std::forward<Args>(A)...);
if (!Mapper)
return Mapper.takeError();
return std::make_unique<MapperJITLinkMemoryManager>(ReservationGranularity,
std::move(*Mapper));
}
void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G,
OnAllocatedFunction OnAllocated) override;
// synchronous overload
using JITLinkMemoryManager::allocate;
void deallocate(std::vector<FinalizedAlloc> Allocs,
OnDeallocatedFunction OnDeallocated) override;
// synchronous overload
using JITLinkMemoryManager::deallocate;
private:
class InFlightAlloc;
std::mutex Mutex;
// We reserve multiples of this from the executor address space
size_t ReservationUnits;
// Ranges that have been reserved in executor but not yet allocated
using AvailableMemoryMap = IntervalMap<ExecutorAddr, bool>;
AvailableMemoryMap::Allocator AMAllocator;
IntervalMap<ExecutorAddr, bool> AvailableMemory;
// Ranges that have been reserved in executor and already allocated
DenseMap<ExecutorAddr, ExecutorAddrDiff> UsedMemory;
std::unique_ptr<MemoryMapper> Mapper;
};
} // end namespace orc
} // end namespace llvm
#endif // LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|