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