1//===---------------- SimpleExecutorMemoryManager.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// A simple allocator class suitable for basic remote-JIT use.
10//
11// FIXME: The functionality in this file should be moved to the ORC runtime.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORMEMORYMANAGER_H
16#define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORMEMORYMANAGER_H
17
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
20#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
21#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
22#include "llvm/ExecutionEngine/Orc/TargetProcess/ExecutorBootstrapService.h"
23#include "llvm/Support/Error.h"
24
25#include <mutex>
26
27namespace llvm {
28namespace orc {
29namespace rt_bootstrap {
30
31/// Simple page-based allocator.
32class SimpleExecutorMemoryManager : public ExecutorBootstrapService {
33public:
34 virtual ~SimpleExecutorMemoryManager();
35
36 Expected<ExecutorAddr> allocate(uint64_t Size);
37 Error finalize(tpctypes::FinalizeRequest &FR);
38 Error deallocate(const std::vector<ExecutorAddr> &Bases);
39
40 Error shutdown() override;
41 void addBootstrapSymbols(StringMap<ExecutorAddr> &M) override;
42
43private:
44 struct Allocation {
45 size_t Size = 0;
46 std::vector<shared::WrapperFunctionCall> DeallocationActions;
47 };
48
49 using AllocationsMap = DenseMap<void *, Allocation>;
50
51 Error deallocateImpl(void *Base, Allocation &A);
52
53 static llvm::orc::shared::CWrapperFunctionResult
54 reserveWrapper(const char *ArgData, size_t ArgSize);
55
56 static llvm::orc::shared::CWrapperFunctionResult
57 finalizeWrapper(const char *ArgData, size_t ArgSize);
58
59 static llvm::orc::shared::CWrapperFunctionResult
60 deallocateWrapper(const char *ArgData, size_t ArgSize);
61
62 std::mutex M;
63 AllocationsMap Allocations;
64};
65
66} // end namespace rt_bootstrap
67} // end namespace orc
68} // end namespace llvm
69
70#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_SIMPLEEXECUTORMEMORYMANAGER_H
71

source code of llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.h