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