Skip to content

Commit

Permalink
[ORC] Add Platform::teardownJITDylib method.
Browse files Browse the repository at this point in the history
This is a counterpart to Platform::setupJITDylib, and is called when JITDylib
instances are removed (via ExecutionSession::removeJITDylib).

Upcoming MachOPlatform patches will use this to clear per-JITDylib data when
JITDylibs are removed.
  • Loading branch information
lhames committed Jan 18, 2022
1 parent ec9cb3a commit ade7164
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions llvm/include/llvm/ExecutionEngine/Orc/Core.h
Expand Up @@ -1309,6 +1309,10 @@ class Platform {
/// __dso_handle).
virtual Error setupJITDylib(JITDylib &JD) = 0;

/// This method will be called outside the session lock each time a JITDylib
/// is removed to allow the Platform to remove any JITDylib-specific data.
virtual Error teardownJITDylib(JITDylib &JD) = 0;

/// This method will be called under the ExecutionSession lock each time a
/// MaterializationUnit is added to a JITDylib.
virtual Error notifyAdding(ResourceTracker &RT,
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h
Expand Up @@ -101,6 +101,7 @@ class ELFNixPlatform : public Platform {
ObjectLinkingLayer &getObjectLinkingLayer() const { return ObjLinkingLayer; }

Error setupJITDylib(JITDylib &JD) override;
Error teardownJITDylib(JITDylib &JD) override;
Error notifyAdding(ResourceTracker &RT,
const MaterializationUnit &MU) override;
Error notifyRemoving(ResourceTracker &RT) override;
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
Expand Up @@ -97,6 +97,7 @@ class MachOPlatform : public Platform {
ObjectLinkingLayer &getObjectLinkingLayer() const { return ObjLinkingLayer; }

Error setupJITDylib(JITDylib &JD) override;
Error teardownJITDylib(JITDylib &JD) override;
Error notifyAdding(ResourceTracker &RT,
const MaterializationUnit &MU) override;
Error notifyRemoving(ResourceTracker &RT) override;
Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/ExecutionEngine/Orc/Core.cpp
Expand Up @@ -1933,9 +1933,14 @@ Error ExecutionSession::removeJITDylib(JITDylib &JD) {
JDs.erase(I);
});

// Clear the JITDylib.
// Clear the JITDylib. Hold on to any error while we clean up the
// JITDylib members below.
auto Err = JD.clear();

// Notify the platform of the teardown.
if (P)
Err = joinErrors(std::move(Err), P->teardownJITDylib(JD));

// Set JD to closed state. Clear remaining data structures.
runSessionLocked([&] {
assert(JD.State == JITDylib::Closing && "JD should be closing");
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
Expand Up @@ -155,6 +155,10 @@ Error ELFNixPlatform::setupJITDylib(JITDylib &JD) {
std::make_unique<DSOHandleMaterializationUnit>(*this, DSOHandleSymbol));
}

Error ELFNixPlatform::teardownJITDylib(JITDylib &JD) {
return Error::success();
}

Error ELFNixPlatform::notifyAdding(ResourceTracker &RT,
const MaterializationUnit &MU) {
auto &JD = RT.getJITDylib();
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
Expand Up @@ -89,6 +89,7 @@ class GenericLLVMIRPlatform : public Platform {
public:
GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
Error setupJITDylib(JITDylib &JD) override;
Error teardownJITDylib(JITDylib &JD) override;
Error notifyAdding(ResourceTracker &RT,
const MaterializationUnit &MU) override;
Error notifyRemoving(ResourceTracker &RT) override {
Expand Down Expand Up @@ -460,6 +461,10 @@ Error GenericLLVMIRPlatform::setupJITDylib(JITDylib &JD) {
return S.setupJITDylib(JD);
}

Error GenericLLVMIRPlatform::teardownJITDylib(JITDylib &JD) {
return Error::success();
}

Error GenericLLVMIRPlatform::notifyAdding(ResourceTracker &RT,
const MaterializationUnit &MU) {
return S.notifyAdding(RT, MU);
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
Expand Up @@ -203,6 +203,8 @@ Error MachOPlatform::setupJITDylib(JITDylib &JD) {
*this, MachOHeaderStartSymbol));
}

Error MachOPlatform::teardownJITDylib(JITDylib &JD) { return Error::success(); }

Error MachOPlatform::notifyAdding(ResourceTracker &RT,
const MaterializationUnit &MU) {
auto &JD = RT.getJITDylib();
Expand Down

0 comments on commit ade7164

Please sign in to comment.