diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h @@ -17,6 +17,8 @@ #include "llvm/ExecutionEngine/Orc/Mangling.h" #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ExtensibleRTTI.h" #include "llvm/Support/MemoryBuffer.h" namespace llvm { @@ -129,8 +131,10 @@ }; /// Interface for Layers that accept object files. -class ObjectLayer { +class ObjectLayer : public RTTIExtends { public: + static char ID; + ObjectLayer(ExecutionSession &ES); virtual ~ObjectLayer(); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h @@ -52,10 +52,13 @@ /// Clients can use this class to add relocatable object files to an /// ExecutionSession, and it typically serves as the base layer (underneath /// a compiling layer like IRCompileLayer) for the rest of the JIT. -class ObjectLinkingLayer : public ObjectLayer, private ResourceManager { +class ObjectLinkingLayer : public RTTIExtends, + private ResourceManager { friend class ObjectLinkingLayerJITLinkContext; public: + static char ID; + /// Plugin instances can be added to the ObjectLinkingLayer to receive /// callbacks when code is loaded or emitted, and when JITLink is being /// configured. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h @@ -22,8 +22,11 @@ namespace llvm { namespace orc { -class ObjectTransformLayer : public ObjectLayer { +class ObjectTransformLayer + : public RTTIExtends { public: + static char ID; + using TransformFunction = std::function>( std::unique_ptr)>; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h @@ -35,8 +35,12 @@ namespace llvm { namespace orc { -class RTDyldObjectLinkingLayer : public ObjectLayer, private ResourceManager { +class RTDyldObjectLinkingLayer + : public RTTIExtends, + private ResourceManager { public: + static char ID; + /// Functor for receiving object-loaded notifications. using NotifyLoadedFunction = std::function; + ObjectLinkingLayer::ObjectLinkingLayer(ExecutionSession &ES, JITLinkMemoryManager &MemMgr) - : ObjectLayer(ES), MemMgr(MemMgr) { + : BaseT(ES), MemMgr(MemMgr) { ES.registerResourceManager(*this); } ObjectLinkingLayer::ObjectLinkingLayer( ExecutionSession &ES, std::unique_ptr MemMgr) - : ObjectLayer(ES), MemMgr(*MemMgr), MemMgrOwnership(std::move(MemMgr)) { + : BaseT(ES), MemMgr(*MemMgr), MemMgrOwnership(std::move(MemMgr)) { ES.registerResourceManager(*this); } diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp @@ -12,10 +12,14 @@ namespace llvm { namespace orc { +char ObjectTransformLayer::ID; + +using BaseT = RTTIExtends; + ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES, - ObjectLayer &BaseLayer, - TransformFunction Transform) - : ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {} + ObjectLayer &BaseLayer, + TransformFunction Transform) + : BaseT(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {} void ObjectTransformLayer::emit( std::unique_ptr R, diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp @@ -75,9 +75,13 @@ namespace llvm { namespace orc { +char RTDyldObjectLinkingLayer::ID; + +using BaseT = RTTIExtends; + RTDyldObjectLinkingLayer::RTDyldObjectLinkingLayer( ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager) - : ObjectLayer(ES), GetMemoryManager(GetMemoryManager) { + : BaseT(ES), GetMemoryManager(GetMemoryManager) { ES.registerResourceManager(*this); } diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -881,10 +881,10 @@ auto J = ExitOnErr(Builder.create()); - if (TT->isOSBinFormatELF()) - static_cast(J->getObjLinkingLayer()) - .registerJITEventListener( - *JITEventListener::createGDBRegistrationListener()); + auto *ObjLayer = &J->getObjLinkingLayer(); + if (auto *RTDyldObjLayer = dyn_cast(ObjLayer)) + RTDyldObjLayer->registerJITEventListener( + *JITEventListener::createGDBRegistrationListener()); if (PerModuleLazy) J->setPartitionFunction(orc::CompileOnDemandLayer::compileWholeModule);