[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / ExecutionEngine / JITLink / JITLinkMemoryManager.h
blob9d0b37fe4a4d71d6443aa14ace324cd911cb9dae
1 //===-- JITLinkMemoryManager.h - JITLink mem manager interface --*- 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 // Contains the JITLinkMemoryManager interface.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_JITLINKMEMORYMANAGER_H
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ExecutionEngine/JITSymbol.h"
18 #include "llvm/Support/Error.h"
19 #include "llvm/Support/Memory.h"
20 #include <cstdint>
22 namespace llvm {
23 namespace jitlink {
25 /// Manages allocations of JIT memory.
26 ///
27 /// Instances of this class may be accessed concurrently from multiple threads
28 /// and their implemetations should include any necessary synchronization.
29 class JITLinkMemoryManager {
30 public:
31 using ProtectionFlags = sys::Memory::ProtectionFlags;
33 class SegmentRequest {
34 public:
35 SegmentRequest() = default;
36 SegmentRequest(size_t ContentSize, unsigned ContentAlign,
37 uint64_t ZeroFillSize, unsigned ZeroFillAlign)
38 : ContentSize(ContentSize), ZeroFillSize(ZeroFillSize),
39 ContentAlign(ContentAlign), ZeroFillAlign(ZeroFillAlign) {}
40 size_t getContentSize() const { return ContentSize; }
41 unsigned getContentAlignment() const { return ContentAlign; }
42 uint64_t getZeroFillSize() const { return ZeroFillSize; }
43 unsigned getZeroFillAlignment() const { return ZeroFillAlign; }
45 private:
46 size_t ContentSize = 0;
47 uint64_t ZeroFillSize = 0;
48 unsigned ContentAlign = 0;
49 unsigned ZeroFillAlign = 0;
52 using SegmentsRequestMap = DenseMap<unsigned, SegmentRequest>;
54 /// Represents an allocation created by the memory manager.
55 ///
56 /// An allocation object is responsible for allocating and owning jit-linker
57 /// working and target memory, and for transfering from working to target
58 /// memory.
59 ///
60 class Allocation {
61 public:
62 using FinalizeContinuation = std::function<void(Error)>;
64 virtual ~Allocation();
66 /// Should return the address of linker working memory for the segment with
67 /// the given protection flags.
68 virtual MutableArrayRef<char> getWorkingMemory(ProtectionFlags Seg) = 0;
70 /// Should return the final address in the target process where the segment
71 /// will reside.
72 virtual JITTargetAddress getTargetMemory(ProtectionFlags Seg) = 0;
74 /// Should transfer from working memory to target memory, and release
75 /// working memory.
76 virtual void finalizeAsync(FinalizeContinuation OnFinalize) = 0;
78 /// Should deallocate target memory.
79 virtual Error deallocate() = 0;
82 virtual ~JITLinkMemoryManager();
84 /// Create an Allocation object.
85 virtual Expected<std::unique_ptr<Allocation>>
86 allocate(const SegmentsRequestMap &Request) = 0;
89 /// A JITLinkMemoryManager that allocates in-process memory.
90 class InProcessMemoryManager : public JITLinkMemoryManager {
91 public:
92 Expected<std::unique_ptr<Allocation>>
93 allocate(const SegmentsRequestMap &Request) override;
96 } // end namespace jitlink
97 } // end namespace llvm
99 #endif // LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H