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-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"
28 class IntelJITEventsWrapper;
29 class MachineFunction;
30 class OProfileWrapper;
36 } // end namespace object
38 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
39 /// about a generated machine code function.
40 struct JITEvent_EmittedFunctionDetails {
42 /// The address at which the current line changes.
45 /// The new location information. These can be translated to DebugLocTuples
46 /// using MF->getDebugLocTuple().
50 /// The machine function the struct contains information for.
51 const MachineFunction *MF;
53 /// The list of line boundary information, sorted by address.
54 std::vector<LineStart> LineStarts;
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.
61 /// The default implementation of each method does nothing.
62 class JITEventListener {
64 using EmittedFunctionDetails = JITEvent_EmittedFunctionDetails;
67 JITEventListener() = default;
68 virtual ~JITEventListener() = default;
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.
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) {}
81 /// NotifyFreeingObject - Called just before the memory associated with
82 /// a previously emitted object is released.
83 virtual void NotifyFreeingObject(const object::ObjectFile &Obj) {}
85 // Get a pointe to the GDB debugger registration listener.
86 static JITEventListener *createGDBRegistrationListener();
88 #if LLVM_USE_INTEL_JITEVENTS
89 // Construct an IntelJITEventListener
90 static JITEventListener *createIntelJITEventListener();
92 // Construct an IntelJITEventListener with a test Intel JIT API implementation
93 static JITEventListener *createIntelJITEventListener(
94 IntelJITEventsWrapper* AlternativeImpl);
96 static JITEventListener *createIntelJITEventListener() { return nullptr; }
98 static JITEventListener *createIntelJITEventListener(
99 IntelJITEventsWrapper* AlternativeImpl) {
102 #endif // USE_INTEL_JITEVENTS
104 #if LLVM_USE_OPROFILE
105 // Construct an OProfileJITEventListener
106 static JITEventListener *createOProfileJITEventListener();
108 // Construct an OProfileJITEventListener with a test opagent implementation
109 static JITEventListener *createOProfileJITEventListener(
110 OProfileWrapper* AlternativeImpl);
112 static JITEventListener *createOProfileJITEventListener() { return nullptr; }
114 static JITEventListener *createOProfileJITEventListener(
115 OProfileWrapper* AlternativeImpl) {
118 #endif // USE_OPROFILE
121 static JITEventListener *createPerfJITEventListener();
123 static JITEventListener *createPerfJITEventListener()
130 virtual void anchor();
133 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITEventListener, LLVMJITEventListenerRef)
135 } // end namespace llvm
137 #endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H