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_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
16 #define LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
18 #include "llvm/Config/config.h"
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/DebugLoc.h"
26 class MachineFunction;
27 class OProfileWrapper;
28 class IntelJITEventsWrapper;
31 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
32 /// about a generated machine code function.
33 struct JITEvent_EmittedFunctionDetails {
35 /// The address at which the current line changes.
38 /// The new location information. These can be translated to DebugLocTuples
39 /// using MF->getDebugLocTuple().
43 /// The machine function the struct contains information for.
44 const MachineFunction *MF;
46 /// The list of line boundary information, sorted by address.
47 std::vector<LineStart> LineStarts;
50 /// JITEventListener - Abstract interface for use by the JIT to notify clients
51 /// about significant events during compilation. For example, to notify
52 /// profilers and debuggers that need to know where functions have been emitted.
54 /// The default implementation of each method does nothing.
55 class JITEventListener {
57 typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
61 virtual ~JITEventListener();
63 /// NotifyFunctionEmitted - Called after a function has been successfully
64 /// emitted to memory. The function still has its MachineFunction attached,
65 /// if you should happen to need that.
66 virtual void NotifyFunctionEmitted(const Function &,
68 const EmittedFunctionDetails &) {}
70 /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after
71 /// the global mapping is removed, but before the machine code is returned to
74 /// OldPtr is the address of the machine code and will be the same as the Code
75 /// parameter to a previous NotifyFunctionEmitted call. The Function passed
76 /// to NotifyFunctionEmitted may have been destroyed by the time of the
77 /// matching NotifyFreeingMachineCode call.
78 virtual void NotifyFreeingMachineCode(void *) {}
80 /// NotifyObjectEmitted - Called after an object has been successfully
81 /// emitted to memory. NotifyFunctionEmitted will not be called for
82 /// individual functions in the object.
84 /// ELF-specific information
85 /// The ObjectImage contains the generated object image
86 /// with section headers updated to reflect the address at which sections
87 /// were loaded and with relocations performed in-place on debug sections.
88 virtual void NotifyObjectEmitted(const ObjectImage &Obj) {}
90 /// NotifyFreeingObject - Called just before the memory associated with
91 /// a previously emitted object is released.
92 virtual void NotifyFreeingObject(const ObjectImage &Obj) {}
94 #if LLVM_USE_INTEL_JITEVENTS
95 // Construct an IntelJITEventListener
96 static JITEventListener *createIntelJITEventListener();
98 // Construct an IntelJITEventListener with a test Intel JIT API implementation
99 static JITEventListener *createIntelJITEventListener(
100 IntelJITEventsWrapper* AlternativeImpl);
102 static JITEventListener *createIntelJITEventListener() { return 0; }
104 static JITEventListener *createIntelJITEventListener(
105 IntelJITEventsWrapper* AlternativeImpl) {
108 #endif // USE_INTEL_JITEVENTS
110 #if LLVM_USE_OPROFILE
111 // Construct an OProfileJITEventListener
112 static JITEventListener *createOProfileJITEventListener();
114 // Construct an OProfileJITEventListener with a test opagent implementation
115 static JITEventListener *createOProfileJITEventListener(
116 OProfileWrapper* AlternativeImpl);
119 static JITEventListener *createOProfileJITEventListener() { return 0; }
121 static JITEventListener *createOProfileJITEventListener(
122 OProfileWrapper* AlternativeImpl) {
125 #endif // USE_OPROFILE
129 } // end namespace llvm.
131 #endif // defined LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H