| 1 | //===---- SimpleRemoteMemoryMapper.cpp - Remote memory mapper ----*- 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 | #include "llvm/ExecutionEngine/Orc/SimpleRemoteMemoryMapper.h" |
| 10 | |
| 11 | #include "llvm/ExecutionEngine/JITLink/JITLink.h" |
| 12 | |
| 13 | namespace llvm::orc { |
| 14 | |
| 15 | SimpleRemoteMemoryMapper::SimpleRemoteMemoryMapper(ExecutionSession &ES, |
| 16 | SimpleMemoryMapBindings B) |
| 17 | : ES(ES), B(std::move(B)) {} |
| 18 | |
| 19 | void SimpleRemoteMemoryMapper::reserve(size_t NumBytes, |
| 20 | OnReservedFunction OnReserved) { |
| 21 | B.Reserve( |
| 22 | [NumBytes, OnReserved = std::move(OnReserved)]( |
| 23 | Expected<ExecutorAddr> Result) mutable { |
| 24 | if (!Result) |
| 25 | return OnReserved(Result.takeError()); |
| 26 | OnReserved(ExecutorAddrRange(*Result, NumBytes)); |
| 27 | }, |
| 28 | ES, B.Instance, static_cast<uint64_t>(NumBytes)); |
| 29 | } |
| 30 | |
| 31 | char *SimpleRemoteMemoryMapper::prepare(jitlink::LinkGraph &G, |
| 32 | ExecutorAddr Addr, size_t ContentSize) { |
| 33 | return G.allocateBuffer(Size: ContentSize).data(); |
| 34 | } |
| 35 | |
| 36 | void SimpleRemoteMemoryMapper::initialize(MemoryMapper::AllocInfo &AI, |
| 37 | OnInitializedFunction OnInitialized) { |
| 38 | |
| 39 | tpctypes::FinalizeRequest FR; |
| 40 | |
| 41 | std::swap(x&: FR.Actions, y&: AI.Actions); |
| 42 | FR.Segments.reserve(n: AI.Segments.size()); |
| 43 | |
| 44 | for (auto Seg : AI.Segments) |
| 45 | FR.Segments.push_back(x: {.RAG: Seg.AG, .Addr: AI.MappingBase + Seg.Offset, |
| 46 | .Size: Seg.ContentSize + Seg.ZeroFillSize, |
| 47 | .Content: ArrayRef<char>(Seg.WorkingMem, Seg.ContentSize)}); |
| 48 | |
| 49 | B.Initialize(std::move(OnInitialized), ES, B.Instance, std::move(FR)); |
| 50 | } |
| 51 | |
| 52 | void SimpleRemoteMemoryMapper::deinitialize( |
| 53 | ArrayRef<ExecutorAddr> Allocations, |
| 54 | MemoryMapper::OnDeinitializedFunction OnDeinitialized) { |
| 55 | B.Deinitialize(std::move(OnDeinitialized), ES, B.Instance, Allocations); |
| 56 | } |
| 57 | |
| 58 | void SimpleRemoteMemoryMapper::release(ArrayRef<ExecutorAddr> Bases, |
| 59 | OnReleasedFunction OnReleased) { |
| 60 | B.Release(std::move(OnReleased), ES, B.Instance, Bases); |
| 61 | } |
| 62 | |
| 63 | } // namespace llvm::orc |
| 64 | |