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_EXECUTION_ENGINE_JIT_EVENTLISTENER_H 16 #define LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H 17 18 #include "llvm/Config/config.h" 19 #include "llvm/Support/DataTypes.h" 20 #include "llvm/Support/DebugLoc.h" 21 22 #include <vector> 23 24 namespace llvm { 25 class Function; 26 class MachineFunction; 27 class OProfileWrapper; 28 class IntelJITEventsWrapper; 29 30 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information 31 /// about a generated machine code function. 32 struct JITEvent_EmittedFunctionDetails { 33 struct LineStart { 34 /// The address at which the current line changes. 35 uintptr_t Address; 36 37 /// The new location information. These can be translated to DebugLocTuples 38 /// using MF->getDebugLocTuple(). 39 DebugLoc Loc; 40 }; 41 42 /// The machine function the struct contains information for. 43 const MachineFunction *MF; 44 45 /// The list of line boundary information, sorted by address. 46 std::vector<LineStart> LineStarts; 47 }; 48 49 /// JITEventListener - Abstract interface for use by the JIT to notify clients 50 /// about significant events during compilation. For example, to notify 51 /// profilers and debuggers that need to know where functions have been emitted. 52 /// 53 /// The default implementation of each method does nothing. 54 class JITEventListener { 55 public: 56 typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails; 57 58 public: 59 JITEventListener() {} 60 virtual ~JITEventListener(); 61 62 /// NotifyFunctionEmitted - Called after a function has been successfully 63 /// emitted to memory. The function still has its MachineFunction attached, 64 /// if you should happen to need that. 65 virtual void NotifyFunctionEmitted(const Function &, 66 void *, size_t, 67 const EmittedFunctionDetails &) {} 68 69 /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after 70 /// the global mapping is removed, but before the machine code is returned to 71 /// the allocator. 72 /// 73 /// OldPtr is the address of the machine code and will be the same as the Code 74 /// parameter to a previous NotifyFunctionEmitted call. The Function passed 75 /// to NotifyFunctionEmitted may have been destroyed by the time of the 76 /// matching NotifyFreeingMachineCode call. 77 virtual void NotifyFreeingMachineCode(void *) {} 78 79 #if LLVM_USE_INTEL_JITEVENTS 80 // Construct an IntelJITEventListener 81 static JITEventListener *createIntelJITEventListener(); 82 83 // Construct an IntelJITEventListener with a test Intel JIT API implementation 84 static JITEventListener *createIntelJITEventListener( 85 IntelJITEventsWrapper* AlternativeImpl); 86 #else 87 static JITEventListener *createIntelJITEventListener() { return 0; } 88 89 static JITEventListener *createIntelJITEventListener( 90 IntelJITEventsWrapper* AlternativeImpl) { 91 return 0; 92 } 93 #endif // USE_INTEL_JITEVENTS 94 95 #if LLVM_USE_OPROFILE 96 // Construct an OProfileJITEventListener 97 static JITEventListener *createOProfileJITEventListener(); 98 99 // Construct an OProfileJITEventListener with a test opagent implementation 100 static JITEventListener *createOProfileJITEventListener( 101 OProfileWrapper* AlternativeImpl); 102 #else 103 104 static JITEventListener *createOProfileJITEventListener() { return 0; } 105 106 static JITEventListener *createOProfileJITEventListener( 107 OProfileWrapper* AlternativeImpl) { 108 return 0; 109 } 110 #endif // USE_OPROFILE 111 112 }; 113 114 } // end namespace llvm. 115 116 #endif // defined LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H 117