DebugObjectManagerPlugin.h 3.0 KB

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