Files
llvm-project/orc-rt/lib/executor/AllocAction.cpp
Lang Hames 88a5429a8c [orc-rt] Add allocation-action execution support. (#157244)
This commit contains executor-side support for ORC allocation actions
(see e50aea58d5).

An AllocAction is a function pointer with type
orc_rt_WrapperFunctionBuffer (*)(const char *ArgData, size_t ArgSize),
along with an associated blob of argument bytes.

An AllocActionPair is a pair of AllocActions, one to be run at memory
finalization time and another to be run at deallocation time.

The runFinalizeActions function can be used to run all non-null finalize
actions in a sequence of AllocActionPairs, returning the corresponding
sequence of deallocation actions on success.

The runDeallocActions function can be used to run a sequence of dealloc
actions returned by runFinalizeActions.
2025-09-07 11:09:28 +10:00

56 lines
1.5 KiB
C++

//===- AllocAction.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// AllocAction and related APIs.
//
//===----------------------------------------------------------------------===//
#include "orc-rt/AllocAction.h"
#include "orc-rt/ScopeExit.h"
namespace orc_rt {
Expected<std::vector<AllocAction>>
runFinalizeActions(std::vector<AllocActionPair> AAPs) {
std::vector<AllocAction> DeallocActions;
auto RunDeallocActions = make_scope_exit([&]() {
while (!DeallocActions.empty()) {
// TODO: Log errors from cleanup dealloc actions.
{
[[maybe_unused]] auto B = DeallocActions.back()();
}
DeallocActions.pop_back();
}
});
for (auto &AAP : AAPs) {
if (AAP.Finalize) {
auto B = AAP.Finalize();
if (const char *ErrMsg = B.getOutOfBandError())
return make_error<StringError>(ErrMsg);
}
if (AAP.Dealloc)
DeallocActions.push_back(std::move(AAP.Dealloc));
}
RunDeallocActions.release();
return DeallocActions;
}
void runDeallocActions(std::vector<AllocAction> DAAs) {
while (!DAAs.empty()) {
// TODO: Log errors from cleanup dealloc actions.
{
[[maybe_unused]] auto B = DAAs.back()();
}
DAAs.pop_back();
}
}
} // namespace orc_rt