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,7 @@ #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/MemoryBuffer.h" namespace llvm { @@ -131,7 +132,15 @@ /// Interface for Layers that accept object files. class ObjectLayer { public: - ObjectLayer(ExecutionSession &ES); + enum class Kind { + JITLink = 1, + RuntimeDyld = 2, + Transform = 3, + }; + + Kind getKind() const { return ObjectLayerKind; } + + ObjectLayer(ExecutionSession &ES, Kind K); virtual ~ObjectLayer(); /// Returns the execution session for this layer. @@ -151,6 +160,7 @@ private: ExecutionSession &ES; + const Kind ObjectLayerKind; }; /// Materializes the given object file (represented by a MemoryBuffer 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 @@ -105,6 +105,10 @@ /// Destruct an ObjectLinkingLayer. ~ObjectLinkingLayer(); + static bool classof(const ObjectLayer *Layer) { + return Layer->getKind() == Kind::JITLink; + } + /// Set an object buffer return function. By default object buffers are /// deleted once the JIT has linked them. If a return function is set then /// it will be called to transfer ownership of the buffer instead. 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 @@ -31,6 +31,10 @@ ObjectTransformLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, TransformFunction Transform = TransformFunction()); + static bool classof(const ObjectLayer *Layer) { + return Layer->getKind() == Kind::Transform; + } + void emit(std::unique_ptr R, std::unique_ptr O) override; 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 @@ -56,6 +56,10 @@ ~RTDyldObjectLinkingLayer(); + static bool classof(const ObjectLayer *Layer) { + return Layer->getKind() == Kind::RuntimeDyld; + } + /// Emit the object. void emit(std::unique_ptr R, std::unique_ptr O) override; diff --git a/llvm/lib/ExecutionEngine/Orc/Layer.cpp b/llvm/lib/ExecutionEngine/Orc/Layer.cpp --- a/llvm/lib/ExecutionEngine/Orc/Layer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Layer.cpp @@ -155,7 +155,8 @@ });); } -ObjectLayer::ObjectLayer(ExecutionSession &ES) : ES(ES) {} +ObjectLayer::ObjectLayer(ExecutionSession &ES, Kind K) + : ES(ES), ObjectLayerKind(K) {} ObjectLayer::~ObjectLayer() {} diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -461,13 +461,14 @@ ObjectLinkingLayer::ObjectLinkingLayer(ExecutionSession &ES, JITLinkMemoryManager &MemMgr) - : ObjectLayer(ES), MemMgr(MemMgr) { + : ObjectLayer(ES, Kind::JITLink), MemMgr(MemMgr) { ES.registerResourceManager(*this); } ObjectLinkingLayer::ObjectLinkingLayer( ExecutionSession &ES, std::unique_ptr MemMgr) - : ObjectLayer(ES), MemMgr(*MemMgr), MemMgrOwnership(std::move(MemMgr)) { + : ObjectLayer(ES, Kind::JITLink), 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 @@ -13,9 +13,10 @@ namespace orc { ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES, - ObjectLayer &BaseLayer, - TransformFunction Transform) - : ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {} + ObjectLayer &BaseLayer, + TransformFunction Transform) + : ObjectLayer(ES, Kind::Transform), 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 @@ -77,7 +77,7 @@ RTDyldObjectLinkingLayer::RTDyldObjectLinkingLayer( ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager) - : ObjectLayer(ES), GetMemoryManager(GetMemoryManager) { + : ObjectLayer(ES, Kind::RuntimeDyld), 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,12 @@ auto J = ExitOnErr(Builder.create()); - if (TT->isOSBinFormatELF()) - static_cast(J->getObjLinkingLayer()) - .registerJITEventListener( - *JITEventListener::createGDBRegistrationListener()); + if (TT->isOSBinFormatELF()) { + if (auto *ObjLayer = + dyn_cast(&J->getObjLinkingLayer())) + ObjLayer->registerJITEventListener( + *JITEventListener::createGDBRegistrationListener()); + } if (PerModuleLazy) J->setPartitionFunction(orc::CompileOnDemandLayer::compileWholeModule);