[llvm] 605df81 - [ORC][JITLink] Switch to unique ownership for EHFrameRegistrars.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 17:00:31 PDT 2020
Author: Lang Hames
Date: 2020-08-26T16:59:45-07:00
New Revision: 605df8112cca3c68f044e4f761a1744c39f52c9d
URL: https://github.com/llvm/llvm-project/commit/605df8112cca3c68f044e4f761a1744c39f52c9d
DIFF: https://github.com/llvm/llvm-project/commit/605df8112cca3c68f044e4f761a1744c39f52c9d.diff
LOG: [ORC][JITLink] Switch to unique ownership for EHFrameRegistrars.
This will make stateful registrars (e.g. a future TargetProcessControl based
registrar) easier to deal with.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
index 72687682f606..72394d7c9985 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
@@ -42,32 +42,11 @@ class EHFrameRegistrar {
/// Registers / Deregisters EH-frames in the current process.
class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
public:
- /// Get a reference to the InProcessEHFrameRegistrar singleton.
- static InProcessEHFrameRegistrar &getInstance();
-
- InProcessEHFrameRegistrar(const InProcessEHFrameRegistrar &) = delete;
- InProcessEHFrameRegistrar &
- operator=(const InProcessEHFrameRegistrar &) = delete;
-
- InProcessEHFrameRegistrar(InProcessEHFrameRegistrar &&) = delete;
- InProcessEHFrameRegistrar &operator=(InProcessEHFrameRegistrar &&) = delete;
-
Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,
- size_t EHFrameSectionSize) override {
- return registerEHFrameSection(
- jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
- EHFrameSectionSize);
- }
+ size_t EHFrameSectionSize) override;
Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,
- size_t EHFrameSectionSize) override {
- return deregisterEHFrameSection(
- jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
- EHFrameSectionSize);
- }
-
-private:
- InProcessEHFrameRegistrar();
+ size_t EHFrameSectionSize) override;
};
using StoreFrameRangeFunction =
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
index fbf9bde8a9d5..cb8ee130ab61 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
@@ -177,7 +177,8 @@ class ObjectLinkingLayer : public ObjectLayer {
class EHFrameRegistrationPlugin : public ObjectLinkingLayer::Plugin {
public:
- EHFrameRegistrationPlugin(jitlink::EHFrameRegistrar &Registrar);
+ EHFrameRegistrationPlugin(
+ std::unique_ptr<jitlink::EHFrameRegistrar> Registrar);
Error notifyEmitted(MaterializationResponsibility &MR) override;
void modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT,
jitlink::PassConfiguration &PassConfig) override;
@@ -192,7 +193,7 @@ class EHFrameRegistrationPlugin : public ObjectLinkingLayer::Plugin {
};
std::mutex EHFramePluginMutex;
- jitlink::EHFrameRegistrar &Registrar;
+ std::unique_ptr<jitlink::EHFrameRegistrar> Registrar;
DenseMap<MaterializationResponsibility *, EHFrameRange> InProcessLinks;
DenseMap<VModuleKey, EHFrameRange> TrackedEHFrameRanges;
std::vector<EHFrameRange> UntrackedEHFrameRanges;
diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
index 54ba9ac39ea6..9eda6fb9ea77 100644
--- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
@@ -763,12 +763,19 @@ Error deregisterEHFrameSection(const void *EHFrameSectionAddr,
EHFrameRegistrar::~EHFrameRegistrar() {}
-InProcessEHFrameRegistrar &InProcessEHFrameRegistrar::getInstance() {
- static InProcessEHFrameRegistrar Instance;
- return Instance;
+Error InProcessEHFrameRegistrar::registerEHFrames(
+ JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
+ return registerEHFrameSection(
+ jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
+ EHFrameSectionSize);
}
-InProcessEHFrameRegistrar::InProcessEHFrameRegistrar() {}
+Error InProcessEHFrameRegistrar::deregisterEHFrames(
+ JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
+ return deregisterEHFrameSection(
+ jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
+ EHFrameSectionSize);
+}
LinkGraphPassFunction
createEHFrameRecorderPass(const Triple &TT,
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 531a71d50b9e..56dec8688441 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -984,7 +984,7 @@ Error LLJITBuilderState::prepareForConstruction() {
ObjLinkingLayer = std::make_unique<ObjectLinkingLayer>(
ES, std::make_unique<jitlink::InProcessMemoryManager>());
ObjLinkingLayer->addPlugin(std::make_unique<EHFrameRegistrationPlugin>(
- jitlink::InProcessEHFrameRegistrar::getInstance()));
+ std::make_unique<jitlink::InProcessEHFrameRegistrar>()));
return std::move(ObjLinkingLayer);
};
}
diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
index 5b828ed84462..50fa23d2f80f 100644
--- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
@@ -536,8 +536,8 @@ Error ObjectLinkingLayer::removeAllModules() {
}
EHFrameRegistrationPlugin::EHFrameRegistrationPlugin(
- EHFrameRegistrar &Registrar)
- : Registrar(Registrar) {}
+ std::unique_ptr<EHFrameRegistrar> Registrar)
+ : Registrar(std::move(Registrar)) {}
void EHFrameRegistrationPlugin::modifyPassConfig(
MaterializationResponsibility &MR, const Triple &TT,
@@ -572,7 +572,7 @@ Error EHFrameRegistrationPlugin::notifyEmitted(
else
UntrackedEHFrameRanges.push_back(EHFrameRange);
- return Registrar.registerEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
+ return Registrar->registerEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
}
Error EHFrameRegistrationPlugin::notifyRemovingModule(VModuleKey K) {
@@ -587,7 +587,7 @@ Error EHFrameRegistrationPlugin::notifyRemovingModule(VModuleKey K) {
TrackedEHFrameRanges.erase(EHFrameRangeItr);
- return Registrar.deregisterEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
+ return Registrar->deregisterEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
}
Error EHFrameRegistrationPlugin::notifyRemovingAllModules() {
@@ -608,9 +608,8 @@ Error EHFrameRegistrationPlugin::notifyRemovingAllModules() {
auto EHFrameRange = EHFrameRanges.back();
assert(EHFrameRange.Addr && "Untracked eh-frame range must not be null");
EHFrameRanges.pop_back();
- Err = joinErrors(std::move(Err),
- Registrar.deregisterEHFrames(EHFrameRange.Addr,
- EHFrameRange.Size));
+ Err = joinErrors(std::move(Err), Registrar->deregisterEHFrames(
+ EHFrameRange.Addr, EHFrameRange.Size));
}
return Err;
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index ff9579bbf5b8..f1cc1f2550b3 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -618,7 +618,7 @@ Session::Session(Triple TT, uint64_t PageSize, Error &Err)
if (!NoExec && !TT.isOSWindows())
ObjLayer.addPlugin(std::make_unique<EHFrameRegistrationPlugin>(
- InProcessEHFrameRegistrar::getInstance()));
+ std::make_unique<InProcessEHFrameRegistrar>()));
ObjLayer.addPlugin(std::make_unique<JITLinkSessionPlugin>(*this));
More information about the llvm-commits
mailing list