diff --git a/orc-rt/include/CMakeLists.txt b/orc-rt/include/CMakeLists.txt index 9413878a47a5..89a92bb895a5 100644 --- a/orc-rt/include/CMakeLists.txt +++ b/orc-rt/include/CMakeLists.txt @@ -12,6 +12,7 @@ set(ORC_RT_HEADERS orc-rt/IntervalSet.h orc-rt/Math.h orc-rt/MemoryFlags.h + orc-rt/ResourceManager.h orc-rt/RTTI.h orc-rt/ScopeExit.h orc-rt/SimplePackedSerialization.h diff --git a/orc-rt/include/orc-rt/ResourceManager.h b/orc-rt/include/orc-rt/ResourceManager.h new file mode 100644 index 000000000000..9710daced952 --- /dev/null +++ b/orc-rt/include/orc-rt/ResourceManager.h @@ -0,0 +1,44 @@ +//===- ResourceManager.h -- Interface for JIT resource managers -*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// ResourceManager class and related APIs. +// +//===----------------------------------------------------------------------===// + +#ifndef ORC_RT_RESOURCEMANAGER_H +#define ORC_RT_RESOURCEMANAGER_H + +#include "orc-rt/Error.h" +#include "orc-rt/move_only_function.h" + +namespace orc_rt { + +/// A ResourceManager manages resources (e.g. JIT'd memory) to support a JIT +/// session. +class ResourceManager { +public: + using OnCompleteFn = move_only_function; + + virtual ~ResourceManager(); + + /// The detach method will be called if the controller disconnects from the + /// session without shutting the session down. + /// + /// Since no further requests for allocation will be made, the ResourceManager + /// may discard any book-keeping data-structures used to support allocation. + /// E.g. a JIT memory manager may discard its free-list, since no further + /// JIT'd allocations will happen. + virtual void detach(OnCompleteFn OnComplete) = 0; + + /// The shutdown operation will be called at the end of the session. + /// The ResourceManager should release all held resources. + virtual void shutdown(OnCompleteFn OnComplete) = 0; +}; +} // namespace orc_rt + +#endif // ORC_RT_RESOURCEMANAGER_H diff --git a/orc-rt/lib/executor/CMakeLists.txt b/orc-rt/lib/executor/CMakeLists.txt index 9213522e66a2..08103251fa19 100644 --- a/orc-rt/lib/executor/CMakeLists.txt +++ b/orc-rt/lib/executor/CMakeLists.txt @@ -1,6 +1,7 @@ set(files orc-rt-executor.cpp AllocAction.cpp + ResourceManager.cpp RTTI.cpp ) diff --git a/orc-rt/lib/executor/ResourceManager.cpp b/orc-rt/lib/executor/ResourceManager.cpp new file mode 100644 index 000000000000..171def567a04 --- /dev/null +++ b/orc-rt/lib/executor/ResourceManager.cpp @@ -0,0 +1,19 @@ +//===- ResourceManager.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 +// +//===----------------------------------------------------------------------===// +// +// Contains the implementation of APIs in the orc-rt/ResourceManager.h header. +// +//===----------------------------------------------------------------------===// + +#include "orc-rt/ResourceManager.h" + +namespace orc_rt { + +ResourceManager::~ResourceManager() = default; + +} // namespace orc_rt