1 //===--------------- MapperJITLinkMemoryManager.h -*- C++ -*---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implements JITLinkMemoryManager using MemoryMapper
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
14 #define LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
15 
16 #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
17 #include "llvm/ExecutionEngine/Orc/Core.h"
18 #include "llvm/ExecutionEngine/Orc/MemoryMapper.h"
19 
20 namespace llvm {
21 namespace orc {
22 
23 class MapperJITLinkMemoryManager : public jitlink::JITLinkMemoryManager {
24 public:
25   MapperJITLinkMemoryManager(std::unique_ptr<MemoryMapper> Mapper);
26 
27   template <class MemoryMapperType, class... Args>
28   static Expected<std::unique_ptr<MapperJITLinkMemoryManager>>
29   CreateWithMapper(Args &&...A) {
30     auto Mapper = MemoryMapperType::Create(std::forward<Args>(A)...);
31     if (!Mapper)
32       return Mapper.takeError();
33 
34     return std::make_unique<MapperJITLinkMemoryManager>(std::move(*Mapper));
35   }
36 
37   void allocate(const jitlink::JITLinkDylib *JD, jitlink::LinkGraph &G,
38                 OnAllocatedFunction OnAllocated) override;
39   // synchronous overload
40   using JITLinkMemoryManager::allocate;
41 
42   void deallocate(std::vector<FinalizedAlloc> Allocs,
43                   OnDeallocatedFunction OnDeallocated) override;
44   // synchronous overload
45   using JITLinkMemoryManager::deallocate;
46 
47 private:
48   class InFlightAlloc;
49 
50   std::unique_ptr<MemoryMapper> Mapper;
51 };
52 
53 } // end namespace orc
54 } // end namespace llvm
55 
56 #endif // LLVM_EXECUTIONENGINE_ORC_MAPPERJITLINKMEMORYMANAGER_H
57