JITEventListener.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the JITEventListener interface, which lets users get
  11. // callbacks when significant events happen during the JIT compilation process.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
  15. #define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
  16. #include "RuntimeDyld.h"
  17. #include "llvm/Config/llvm-config.h"
  18. #include "llvm/IR/DebugLoc.h"
  19. #include "llvm/Support/DataTypes.h"
  20. #include <vector>
  21. namespace llvm {
  22. class Function;
  23. class MachineFunction;
  24. class OProfileWrapper;
  25. class IntelJITEventsWrapper;
  26. namespace object {
  27. class ObjectFile;
  28. }
  29. /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
  30. /// about a generated machine code function.
  31. struct JITEvent_EmittedFunctionDetails {
  32. struct LineStart {
  33. /// The address at which the current line changes.
  34. uintptr_t Address;
  35. /// The new location information. These can be translated to DebugLocTuples
  36. /// using MF->getDebugLocTuple().
  37. DebugLoc Loc;
  38. };
  39. /// The machine function the struct contains information for.
  40. const MachineFunction *MF;
  41. /// The list of line boundary information, sorted by address.
  42. std::vector<LineStart> LineStarts;
  43. };
  44. /// JITEventListener - Abstract interface for use by the JIT to notify clients
  45. /// about significant events during compilation. For example, to notify
  46. /// profilers and debuggers that need to know where functions have been emitted.
  47. ///
  48. /// The default implementation of each method does nothing.
  49. class JITEventListener {
  50. public:
  51. typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
  52. public:
  53. JITEventListener() {}
  54. virtual ~JITEventListener() {}
  55. /// NotifyObjectEmitted - Called after an object has been successfully
  56. /// emitted to memory. NotifyFunctionEmitted will not be called for
  57. /// individual functions in the object.
  58. ///
  59. /// ELF-specific information
  60. /// The ObjectImage contains the generated object image
  61. /// with section headers updated to reflect the address at which sections
  62. /// were loaded and with relocations performed in-place on debug sections.
  63. virtual void NotifyObjectEmitted(const object::ObjectFile &Obj,
  64. const RuntimeDyld::LoadedObjectInfo &L) {}
  65. /// NotifyFreeingObject - Called just before the memory associated with
  66. /// a previously emitted object is released.
  67. virtual void NotifyFreeingObject(const object::ObjectFile &Obj) {}
  68. // Get a pointe to the GDB debugger registration listener.
  69. static JITEventListener *createGDBRegistrationListener();
  70. #if LLVM_USE_INTEL_JITEVENTS
  71. // Construct an IntelJITEventListener
  72. static JITEventListener *createIntelJITEventListener();
  73. // Construct an IntelJITEventListener with a test Intel JIT API implementation
  74. static JITEventListener *createIntelJITEventListener(
  75. IntelJITEventsWrapper* AlternativeImpl);
  76. #else
  77. static JITEventListener *createIntelJITEventListener() { return nullptr; }
  78. static JITEventListener *createIntelJITEventListener(
  79. IntelJITEventsWrapper* AlternativeImpl) {
  80. return nullptr;
  81. }
  82. #endif // USE_INTEL_JITEVENTS
  83. #if LLVM_USE_OPROFILE
  84. // Construct an OProfileJITEventListener
  85. static JITEventListener *createOProfileJITEventListener();
  86. // Construct an OProfileJITEventListener with a test opagent implementation
  87. static JITEventListener *createOProfileJITEventListener(
  88. OProfileWrapper* AlternativeImpl);
  89. #else
  90. static JITEventListener *createOProfileJITEventListener() { return nullptr; }
  91. static JITEventListener *createOProfileJITEventListener(
  92. OProfileWrapper* AlternativeImpl) {
  93. return nullptr;
  94. }
  95. #endif // USE_OPROFILE
  96. private:
  97. virtual void anchor();
  98. };
  99. } // end namespace llvm.
  100. #endif // defined LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H