LLVM 22.0.0git
AllocationActions.h
Go to the documentation of this file.
1//===- AllocationActions.h -- JITLink allocation support calls -*- 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// Structures for making memory allocation support calls.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_ALLOCATIONACTIONS_H
14#define LLVM_EXECUTIONENGINE_ORC_SHARED_ALLOCATIONACTIONS_H
15
20#include "llvm/Support/Memory.h"
21
22#include <vector>
23
24namespace llvm {
25namespace orc {
26namespace shared {
27
28/// A pair of WrapperFunctionCalls, one to be run at finalization time, one to
29/// be run at deallocation time.
30///
31/// AllocActionCallPairs should be constructed for paired operations (e.g.
32/// __register_ehframe and __deregister_ehframe for eh-frame registration).
33/// See comments for AllocActions for execution ordering.
34///
35/// For unpaired operations one or the other member can be left unused, as
36/// AllocationActionCalls with an FnAddr of zero will be skipped.
40};
41
42/// A vector of allocation actions to be run for this allocation.
43///
44/// Finalize allocations will be run in order at finalize time. Dealloc
45/// actions will be run in reverse order at deallocation time.
46using AllocActions = std::vector<AllocActionCallPair>;
47
48/// Returns the number of deallocaton actions in the given AllocActions array.
49///
50/// This can be useful if clients want to pre-allocate room for deallocation
51/// actions with the rest of their memory.
52inline size_t numDeallocActions(const AllocActions &AAs) {
53 return llvm::count_if(
54 AAs, [](const AllocActionCallPair &P) { return !!P.Dealloc; });
55}
56
58 unique_function<void(Expected<std::vector<WrapperFunctionCall>>)>;
59
60/// Run finalize actions.
61///
62/// If any finalize action fails then the corresponding dealloc actions will be
63/// run in reverse order (not including the deallocation action for the failed
64/// finalize action), and the error for the failing action will be returned.
65///
66/// If all finalize actions succeed then a vector of deallocation actions will
67/// be returned. The dealloc actions should be run by calling
68/// runDeallocationActions. If this function succeeds then the AA argument will
69/// be cleared before the function returns.
72
74
75/// Run deallocation actions.
76/// Dealloc actions will be run in reverse order (from last element of DAs to
77/// first).
80
83
84template <>
88
89public:
90 static size_t size(const AllocActionCallPair &AAP) {
91 return AL::size(AAP.Finalize, AAP.Dealloc);
92 }
93
94 static bool serialize(SPSOutputBuffer &OB,
95 const AllocActionCallPair &AAP) {
96 return AL::serialize(OB, AAP.Finalize, AAP.Dealloc);
97 }
98
99 static bool deserialize(SPSInputBuffer &IB,
100 AllocActionCallPair &AAP) {
101 return AL::deserialize(IB, AAP.Finalize, AAP.Dealloc);
102 }
103};
104
105} // end namespace shared
106} // end namespace orc
107} // end namespace llvm
108
109#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_ALLOCATIONACTIONS_H
#define LLVM_ABI
Definition: Compiler.h:213
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
#define P(N)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
A utility class for serializing to a blob from a variadic list.
Input char buffer with underflow check.
Output char buffer with overflow check.
static bool serialize(SPSOutputBuffer &OB, const AllocActionCallPair &AAP)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
SPSArgList< SPSTagTs... > AsArgList
Convenience typedef of the corresponding arg list.
Represents a serialized wrapper function call.
unique_function is a type-erasing functor similar to std::function.
size_t numDeallocActions(const AllocActions &AAs)
Returns the number of deallocaton actions in the given AllocActions array.
LLVM_ABI void runDeallocActions(ArrayRef< WrapperFunctionCall > DAs, OnRunDeallocActionsComeleteFn OnComplete)
Run deallocation actions.
LLVM_ABI void runFinalizeActions(AllocActions &AAs, OnRunFinalizeActionsCompleteFn OnComplete)
Run finalize actions.
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition: STLExtras.h:1980
A pair of WrapperFunctionCalls, one to be run at finalization time, one to be run at deallocation tim...