Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 14 | pmbaty | 1 | //===---- DebugObjectManagerPlugin.h - JITLink debug objects ---*- 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 | // ObjectLinkingLayer plugin for emitting debug objects. |
||
| 10 | // |
||
| 11 | //===----------------------------------------------------------------------===// |
||
| 12 | |||
| 13 | #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H |
||
| 14 | #define LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H |
||
| 15 | |||
| 16 | #include "llvm/ADT/Triple.h" |
||
| 17 | #include "llvm/ExecutionEngine/JITLink/JITLink.h" |
||
| 18 | #include "llvm/ExecutionEngine/Orc/Core.h" |
||
| 19 | #include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h" |
||
| 20 | #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" |
||
| 21 | #include "llvm/Support/Error.h" |
||
| 22 | #include "llvm/Support/Memory.h" |
||
| 23 | #include "llvm/Support/MemoryBufferRef.h" |
||
| 24 | |||
| 25 | #include <functional> |
||
| 26 | #include <map> |
||
| 27 | #include <memory> |
||
| 28 | #include <mutex> |
||
| 29 | |||
| 30 | namespace llvm { |
||
| 31 | namespace orc { |
||
| 32 | |||
| 33 | class DebugObject; |
||
| 34 | |||
| 35 | /// Creates and manages DebugObjects for JITLink artifacts. |
||
| 36 | /// |
||
| 37 | /// DebugObjects are created when linking for a MaterializationResponsibility |
||
| 38 | /// starts. They are pending as long as materialization is in progress. |
||
| 39 | /// |
||
| 40 | /// There can only be one pending DebugObject per MaterializationResponsibility. |
||
| 41 | /// If materialization fails, pending DebugObjects are discarded. |
||
| 42 | /// |
||
| 43 | /// Once executable code for the MaterializationResponsibility is emitted, the |
||
| 44 | /// corresponding DebugObject is finalized to target memory and the provided |
||
| 45 | /// DebugObjectRegistrar is notified. Ownership of DebugObjects remains with the |
||
| 46 | /// plugin. |
||
| 47 | /// |
||
| 48 | class DebugObjectManagerPlugin : public ObjectLinkingLayer::Plugin { |
||
| 49 | public: |
||
| 50 | DebugObjectManagerPlugin(ExecutionSession &ES, |
||
| 51 | std::unique_ptr<DebugObjectRegistrar> Target); |
||
| 52 | ~DebugObjectManagerPlugin(); |
||
| 53 | |||
| 54 | void notifyMaterializing(MaterializationResponsibility &MR, |
||
| 55 | jitlink::LinkGraph &G, jitlink::JITLinkContext &Ctx, |
||
| 56 | MemoryBufferRef InputObject) override; |
||
| 57 | |||
| 58 | Error notifyEmitted(MaterializationResponsibility &MR) override; |
||
| 59 | Error notifyFailed(MaterializationResponsibility &MR) override; |
||
| 60 | Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override; |
||
| 61 | |||
| 62 | void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, |
||
| 63 | ResourceKey SrcKey) override; |
||
| 64 | |||
| 65 | void modifyPassConfig(MaterializationResponsibility &MR, |
||
| 66 | jitlink::LinkGraph &LG, |
||
| 67 | jitlink::PassConfiguration &PassConfig) override; |
||
| 68 | |||
| 69 | private: |
||
| 70 | ExecutionSession &ES; |
||
| 71 | |||
| 72 | using OwnedDebugObject = std::unique_ptr<DebugObject>; |
||
| 73 | std::map<MaterializationResponsibility *, OwnedDebugObject> PendingObjs; |
||
| 74 | std::map<ResourceKey, std::vector<OwnedDebugObject>> RegisteredObjs; |
||
| 75 | |||
| 76 | std::mutex PendingObjsLock; |
||
| 77 | std::mutex RegisteredObjsLock; |
||
| 78 | |||
| 79 | std::unique_ptr<DebugObjectRegistrar> Target; |
||
| 80 | }; |
||
| 81 | |||
| 82 | } // namespace orc |
||
| 83 | } // namespace llvm |
||
| 84 | |||
| 85 | #endif // LLVM_EXECUTIONENGINE_ORC_DEBUGOBJECTMANAGERPLUGIN_H |