1 //===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the JITEventListener interface, which lets users get
11 // callbacks when significant events happen during the JIT compilation process.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
16 #define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
18 #include "llvm/Config/llvm-config.h"
19 #include "llvm/ExecutionEngine/RuntimeDyld.h"
20 #include "llvm/IR/DebugLoc.h"
26 class IntelJITEventsWrapper;
27 class MachineFunction;
28 class OProfileWrapper;
34 } // end namespace object
36 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
37 /// about a generated machine code function.
38 struct JITEvent_EmittedFunctionDetails {
40 /// The address at which the current line changes.
43 /// The new location information. These can be translated to DebugLocTuples
44 /// using MF->getDebugLocTuple().
48 /// The machine function the struct contains information for.
49 const MachineFunction *MF;
51 /// The list of line boundary information, sorted by address.
52 std::vector<LineStart> LineStarts;
55 /// JITEventListener - Abstract interface for use by the JIT to notify clients
56 /// about significant events during compilation. For example, to notify
57 /// profilers and debuggers that need to know where functions have been emitted.
59 /// The default implementation of each method does nothing.
60 class JITEventListener {
62 using EmittedFunctionDetails = JITEvent_EmittedFunctionDetails;
65 JITEventListener() = default;
66 virtual ~JITEventListener() = default;
68 /// NotifyObjectEmitted - Called after an object has been successfully
69 /// emitted to memory. NotifyFunctionEmitted will not be called for
70 /// individual functions in the object.
72 /// ELF-specific information
73 /// The ObjectImage contains the generated object image
74 /// with section headers updated to reflect the address at which sections
75 /// were loaded and with relocations performed in-place on debug sections.
76 virtual void NotifyObjectEmitted(const object::ObjectFile &Obj,
77 const RuntimeDyld::LoadedObjectInfo &L) {}
79 /// NotifyFreeingObject - Called just before the memory associated with
80 /// a previously emitted object is released.
81 virtual void NotifyFreeingObject(const object::ObjectFile &Obj) {}
83 // Get a pointe to the GDB debugger registration listener.
84 static JITEventListener *createGDBRegistrationListener();
86 #if LLVM_USE_INTEL_JITEVENTS
87 // Construct an IntelJITEventListener
88 static JITEventListener *createIntelJITEventListener();
90 // Construct an IntelJITEventListener with a test Intel JIT API implementation
91 static JITEventListener *createIntelJITEventListener(
92 IntelJITEventsWrapper* AlternativeImpl);
94 static JITEventListener *createIntelJITEventListener() { return nullptr; }
96 static JITEventListener *createIntelJITEventListener(
97 IntelJITEventsWrapper* AlternativeImpl) {
100 #endif // USE_INTEL_JITEVENTS
102 #if LLVM_USE_OPROFILE
103 // Construct an OProfileJITEventListener
104 static JITEventListener *createOProfileJITEventListener();
106 // Construct an OProfileJITEventListener with a test opagent implementation
107 static JITEventListener *createOProfileJITEventListener(
108 OProfileWrapper* AlternativeImpl);
110 static JITEventListener *createOProfileJITEventListener() { return nullptr; }
112 static JITEventListener *createOProfileJITEventListener(
113 OProfileWrapper* AlternativeImpl) {
116 #endif // USE_OPROFILE
119 virtual void anchor();
122 } // end namespace llvm
124 #endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H