JITEventListener.h revision 341825
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
15#ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
16#define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
17
18#include "llvm-c/ExecutionEngine.h"
19#include "llvm/Config/llvm-config.h"
20#include "llvm/ExecutionEngine/RuntimeDyld.h"
21#include "llvm/IR/DebugLoc.h"
22#include "llvm/Support/CBindingWrapping.h"
23#include <cstdint>
24#include <vector>
25
26namespace llvm {
27
28class IntelJITEventsWrapper;
29class MachineFunction;
30class OProfileWrapper;
31
32namespace object {
33
34class ObjectFile;
35
36} // end namespace object
37
38/// JITEvent_EmittedFunctionDetails - Helper struct for containing information
39/// about a generated machine code function.
40struct JITEvent_EmittedFunctionDetails {
41  struct LineStart {
42    /// The address at which the current line changes.
43    uintptr_t Address;
44
45    /// The new location information.  These can be translated to DebugLocTuples
46    /// using MF->getDebugLocTuple().
47    DebugLoc Loc;
48  };
49
50  /// The machine function the struct contains information for.
51  const MachineFunction *MF;
52
53  /// The list of line boundary information, sorted by address.
54  std::vector<LineStart> LineStarts;
55};
56
57/// JITEventListener - Abstract interface for use by the JIT to notify clients
58/// about significant events during compilation. For example, to notify
59/// profilers and debuggers that need to know where functions have been emitted.
60///
61/// The default implementation of each method does nothing.
62class JITEventListener {
63public:
64  using EmittedFunctionDetails = JITEvent_EmittedFunctionDetails;
65
66public:
67  JITEventListener() = default;
68  virtual ~JITEventListener() = default;
69
70  /// NotifyObjectEmitted - Called after an object has been successfully
71  /// emitted to memory.  NotifyFunctionEmitted will not be called for
72  /// individual functions in the object.
73  ///
74  /// ELF-specific information
75  /// The ObjectImage contains the generated object image
76  /// with section headers updated to reflect the address at which sections
77  /// were loaded and with relocations performed in-place on debug sections.
78  virtual void NotifyObjectEmitted(const object::ObjectFile &Obj,
79                                   const RuntimeDyld::LoadedObjectInfo &L) {}
80
81  /// NotifyFreeingObject - Called just before the memory associated with
82  /// a previously emitted object is released.
83  virtual void NotifyFreeingObject(const object::ObjectFile &Obj) {}
84
85  // Get a pointe to the GDB debugger registration listener.
86  static JITEventListener *createGDBRegistrationListener();
87
88#if LLVM_USE_INTEL_JITEVENTS
89  // Construct an IntelJITEventListener
90  static JITEventListener *createIntelJITEventListener();
91
92  // Construct an IntelJITEventListener with a test Intel JIT API implementation
93  static JITEventListener *createIntelJITEventListener(
94                                      IntelJITEventsWrapper* AlternativeImpl);
95#else
96  static JITEventListener *createIntelJITEventListener() { return nullptr; }
97
98  static JITEventListener *createIntelJITEventListener(
99                                      IntelJITEventsWrapper* AlternativeImpl) {
100    return nullptr;
101  }
102#endif // USE_INTEL_JITEVENTS
103
104#if LLVM_USE_OPROFILE
105  // Construct an OProfileJITEventListener
106  static JITEventListener *createOProfileJITEventListener();
107
108  // Construct an OProfileJITEventListener with a test opagent implementation
109  static JITEventListener *createOProfileJITEventListener(
110                                      OProfileWrapper* AlternativeImpl);
111#else
112  static JITEventListener *createOProfileJITEventListener() { return nullptr; }
113
114  static JITEventListener *createOProfileJITEventListener(
115                                      OProfileWrapper* AlternativeImpl) {
116    return nullptr;
117  }
118#endif // USE_OPROFILE
119
120#if LLVM_USE_PERF
121  static JITEventListener *createPerfJITEventListener();
122#else
123  static JITEventListener *createPerfJITEventListener()
124  {
125    return nullptr;
126  }
127#endif // USE_PERF
128
129private:
130  virtual void anchor();
131};
132
133DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITEventListener, LLVMJITEventListenerRef)
134
135} // end namespace llvm
136
137#endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
138