LLVM 20.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
18#include "llvm/Support/Memory.h"
19
20#include <vector>
21
22namespace llvm {
23namespace orc {
24namespace shared {
25
26/// A pair of WrapperFunctionCalls, one to be run at finalization time, one to
27/// be run at deallocation time.
28///
29/// AllocActionCallPairs should be constructed for paired operations (e.g.
30/// __register_ehframe and __deregister_ehframe for eh-frame registration).
31/// See comments for AllocActions for execution ordering.
32///
33/// For unpaired operations one or the other member can be left unused, as
34/// AllocationActionCalls with an FnAddr of zero will be skipped.
38};
39
40/// A vector of allocation actions to be run for this allocation.
41///
42/// Finalize allocations will be run in order at finalize time. Dealloc
43/// actions will be run in reverse order at deallocation time.
44using AllocActions = std::vector<AllocActionCallPair>;
45
46/// Returns the number of deallocaton actions in the given AllocActions array.
47///
48/// This can be useful if clients want to pre-allocate room for deallocation
49/// actions with the rest of their memory.
50inline size_t numDeallocActions(const AllocActions &AAs) {
51 return llvm::count_if(
52 AAs, [](const AllocActionCallPair &P) { return !!P.Dealloc; });
53}
54
55/// Run finalize actions.
56///
57/// If any finalize action fails then the corresponding dealloc actions will be
58/// run in reverse order (not including the deallocation action for the failed
59/// finalize action), and the error for the failing action will be returned.
60///
61/// If all finalize actions succeed then a vector of deallocation actions will
62/// be returned. The dealloc actions should be run by calling
63/// runDeallocationActions. If this function succeeds then the AA argument will
64/// be cleared before the function returns.
67
68/// Run deallocation actions.
69/// Dealloc actions will be run in reverse order (from last element of DAs to
70/// first).
72
75
76template <>
80
81public:
82 static size_t size(const AllocActionCallPair &AAP) {
83 return AL::size(AAP.Finalize, AAP.Dealloc);
84 }
85
86 static bool serialize(SPSOutputBuffer &OB,
87 const AllocActionCallPair &AAP) {
88 return AL::serialize(OB, AAP.Finalize, AAP.Dealloc);
89 }
90
91 static bool deserialize(SPSInputBuffer &IB,
93 return AL::deserialize(IB, AAP.Finalize, AAP.Dealloc);
94 }
95};
96
97} // end namespace shared
98} // end namespace orc
99} // end namespace llvm
100
101#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_ALLOCATIONACTIONS_H
#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:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
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.
size_t numDeallocActions(const AllocActions &AAs)
Returns the number of deallocaton actions in the given AllocActions array.
Error runDeallocActions(ArrayRef< WrapperFunctionCall > DAs)
Run deallocation actions.
Expected< std::vector< WrapperFunctionCall > > runFinalizeActions(AllocActions &AAs)
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:1921
A pair of WrapperFunctionCalls, one to be run at finalization time, one to be run at deallocation tim...