| 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 | |
| 11 | namespace llvm { |
| 12 | namespace orc { |
| 13 | namespace shared { |
| 14 | |
| 15 | void runFinalizeActions(AllocActions &AAs, |
| 16 | OnRunFinalizeActionsCompleteFn OnComplete) { |
| 17 | std::vector<WrapperFunctionCall> DeallocActions; |
| 18 | DeallocActions.reserve(n: numDeallocActions(AAs)); |
| 19 | |
| 20 | for (auto &AA : AAs) { |
| 21 | if (AA.Finalize) |
| 22 | |
| 23 | if (auto Err = AA.Finalize.runWithSPSRetErrorMerged()) { |
| 24 | while (!DeallocActions.empty()) { |
| 25 | Err = joinErrors(E1: std::move(Err), |
| 26 | E2: DeallocActions.back().runWithSPSRetErrorMerged()); |
| 27 | DeallocActions.pop_back(); |
| 28 | } |
| 29 | return OnComplete(std::move(Err)); |
| 30 | } |
| 31 | |
| 32 | if (AA.Dealloc) |
| 33 | DeallocActions.push_back(x: std::move(AA.Dealloc)); |
| 34 | } |
| 35 | |
| 36 | AAs.clear(); |
| 37 | OnComplete(std::move(DeallocActions)); |
| 38 | } |
| 39 | |
| 40 | void runDeallocActions(ArrayRef<WrapperFunctionCall> DAs, |
| 41 | OnRunDeallocActionsComeleteFn OnComplete) { |
| 42 | Error Err = Error::success(); |
| 43 | while (!DAs.empty()) { |
| 44 | Err = joinErrors(E1: std::move(Err), E2: DAs.back().runWithSPSRetErrorMerged()); |
| 45 | DAs = DAs.drop_back(); |
| 46 | } |
| 47 | OnComplete(std::move(Err)); |
| 48 | } |
| 49 | |
| 50 | } // namespace shared |
| 51 | } // namespace orc |
| 52 | } // namespace llvm |
| 53 |