02350b6a950ce8f6829690521482a5a3fda4dbeb
[oota-llvm.git] / include / llvm / ExecutionEngine / JITEventListener.h
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 "llvm/Config/llvm-config.h"
19 #include "llvm/IR/DebugLoc.h"
20 #include "llvm/Support/DataTypes.h"
21 #include <vector>
22
23 namespace llvm {
24 class Function;
25 class MachineFunction;
26 class OProfileWrapper;
27 class IntelJITEventsWrapper;
28 class ObjectImage;
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   /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after
63   /// the global mapping is removed, but before the machine code is returned to
64   /// the allocator.
65   ///
66   /// OldPtr is the address of the machine code and will be the same as the Code
67   /// parameter to a previous NotifyFunctionEmitted call.  The Function passed
68   /// to NotifyFunctionEmitted may have been destroyed by the time of the
69   /// matching NotifyFreeingMachineCode call.
70   virtual void NotifyFreeingMachineCode(void *) {}
71
72   /// NotifyObjectEmitted - Called after an object has been successfully
73   /// emitted to memory.  NotifyFunctionEmitted will not be called for
74   /// individual functions in the object.
75   ///
76   /// ELF-specific information
77   /// The ObjectImage contains the generated object image
78   /// with section headers updated to reflect the address at which sections
79   /// were loaded and with relocations performed in-place on debug sections.
80   virtual void NotifyObjectEmitted(const ObjectImage &Obj) {}
81
82   /// NotifyFreeingObject - Called just before the memory associated with
83   /// a previously emitted object is released.
84   virtual void NotifyFreeingObject(const ObjectImage &Obj) {}
85
86 #if LLVM_USE_INTEL_JITEVENTS
87   // Construct an IntelJITEventListener
88   static JITEventListener *createIntelJITEventListener();
89
90   // Construct an IntelJITEventListener with a test Intel JIT API implementation
91   static JITEventListener *createIntelJITEventListener(
92                                       IntelJITEventsWrapper* AlternativeImpl);
93 #else
94   static JITEventListener *createIntelJITEventListener() { return nullptr; }
95
96   static JITEventListener *createIntelJITEventListener(
97                                       IntelJITEventsWrapper* AlternativeImpl) {
98     return nullptr;
99   }
100 #endif // USE_INTEL_JITEVENTS
101
102 #if LLVM_USE_OPROFILE
103   // Construct an OProfileJITEventListener
104   static JITEventListener *createOProfileJITEventListener();
105
106   // Construct an OProfileJITEventListener with a test opagent implementation
107   static JITEventListener *createOProfileJITEventListener(
108                                       OProfileWrapper* AlternativeImpl);
109 #else
110
111   static JITEventListener *createOProfileJITEventListener() { return nullptr; }
112
113   static JITEventListener *createOProfileJITEventListener(
114                                       OProfileWrapper* AlternativeImpl) {
115     return nullptr;
116   }
117 #endif // USE_OPROFILE
118
119 };
120
121 } // end namespace llvm.
122
123 #endif // defined LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H