Skip to content

Commit f5a97bf

Browse files
lhamessvkeerthy
authored andcommitted
[orc-rt] Add ResourceManager interface.
The ResourceManager interface can be used to implement ownership for resources allocated to JIT'd code, e.g. memory and metadata registrations (frame info, language runtime metadata, etc.). Resources can be *deallocated*, meaning that they should be cleaned up (memory released, registrations deregistered, etc.), or they can be *detached*, meaning that cleanup should be performed automatically when the ResourceManager itself is destroyed. The intent is to allow JIT'd code to continue running after the llvm::orc::ExecutionSession that produced it is disconnected / destroyed.
1 parent 99e4d08 commit f5a97bf

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

orc-rt/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(ORC_RT_HEADERS
1212
orc-rt/IntervalSet.h
1313
orc-rt/Math.h
1414
orc-rt/MemoryFlags.h
15+
orc-rt/ResourceManager.h
1516
orc-rt/RTTI.h
1617
orc-rt/ScopeExit.h
1718
orc-rt/SimplePackedSerialization.h
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===- ResourceManager.h -- Interface for JIT resource managers -*- 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+
// ResourceManager class and related APIs.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef ORC_RT_RESOURCEMANAGER_H
14+
#define ORC_RT_RESOURCEMANAGER_H
15+
16+
#include "orc-rt/Error.h"
17+
#include "orc-rt/move_only_function.h"
18+
19+
namespace orc_rt {
20+
21+
/// A ResourceManager manages resources (e.g. JIT'd memory) to support a JIT
22+
/// session.
23+
class ResourceManager {
24+
public:
25+
using OnCompleteFn = move_only_function<void(Error)>;
26+
27+
virtual ~ResourceManager();
28+
29+
/// The detach method will be called if the controller disconnects from the
30+
/// session without shutting the session down.
31+
///
32+
/// Since no further requests for allocation will be made, the ResourceManager
33+
/// may discard any book-keeping data-structures used to support allocation.
34+
/// E.g. a JIT memory manager may discard its free-list, since no further
35+
/// JIT'd allocations will happen.
36+
virtual void detach(OnCompleteFn OnComplete) = 0;
37+
38+
/// The shutdown operation will be called at the end of the session.
39+
/// The ResourceManager should release all held resources.
40+
virtual void shutdown(OnCompleteFn OnComplete) = 0;
41+
};
42+
} // namespace orc_rt
43+
44+
#endif // ORC_RT_RESOURCEMANAGER_H

orc-rt/lib/executor/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(files
22
orc-rt-executor.cpp
33
AllocAction.cpp
4+
ResourceManager.cpp
45
RTTI.cpp
56
)
67

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===- ResourceManager.cpp ------------------------------------------------===//
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+
// Contains the implementation of APIs in the orc-rt/ResourceManager.h header.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "orc-rt/ResourceManager.h"
14+
15+
namespace orc_rt {
16+
17+
ResourceManager::~ResourceManager() = default;
18+
19+
} // namespace orc_rt

0 commit comments

Comments
 (0)