1//===----- AllocationActions.gpp -- JITLink allocation support calls -----===//
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#include "llvm/ExecutionEngine/Orc/Shared/AllocationActions.h"
10
11namespace llvm {
12namespace orc {
13namespace shared {
14
15Expected<std::vector<WrapperFunctionCall>>
16runFinalizeActions(AllocActions &AAs) {
17 std::vector<WrapperFunctionCall> DeallocActions;
18 DeallocActions.reserve(n: numDeallocActions(AAs));
19
20 for (auto &AA : AAs) {
21 if (AA.Finalize)
22 if (auto Err = AA.Finalize.runWithSPSRetErrorMerged())
23 return joinErrors(E1: std::move(Err), E2: runDeallocActions(DAs: DeallocActions));
24
25 if (AA.Dealloc)
26 DeallocActions.push_back(x: std::move(AA.Dealloc));
27 }
28
29 AAs.clear();
30 return DeallocActions;
31}
32
33Error runDeallocActions(ArrayRef<WrapperFunctionCall> DAs) {
34 Error Err = Error::success();
35 while (!DAs.empty()) {
36 Err = joinErrors(E1: std::move(Err), E2: DAs.back().runWithSPSRetErrorMerged());
37 DAs = DAs.drop_back();
38 }
39 return Err;
40}
41
42} // namespace shared
43} // namespace orc
44} // namespace llvm
45