]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/llvm/ExecutionEngine/JITEventListener.h
Vendor import of llvm release_32 branch r168974 (effectively, 3.2 RC2):
[FreeBSD/FreeBSD.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_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 class ObjectImage;
30
31 /// JITEvent_EmittedFunctionDetails - Helper struct for containing information
32 /// about a generated machine code function.
33 struct JITEvent_EmittedFunctionDetails {
34   struct LineStart {
35     /// The address at which the current line changes.
36     uintptr_t Address;
37
38     /// The new location information.  These can be translated to DebugLocTuples
39     /// using MF->getDebugLocTuple().
40     DebugLoc Loc;
41   };
42
43   /// The machine function the struct contains information for.
44   const MachineFunction *MF;
45
46   /// The list of line boundary information, sorted by address.
47   std::vector<LineStart> LineStarts;
48 };
49
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.
53 ///
54 /// The default implementation of each method does nothing.
55 class JITEventListener {
56 public:
57   typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
58
59 public:
60   JITEventListener() {}
61   virtual ~JITEventListener();
62
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 &,
67                                      void *, size_t,
68                                      const EmittedFunctionDetails &) {}
69
70   /// NotifyFreeingMachineCode - Called from freeMachineCodeForFunction(), after
71   /// the global mapping is removed, but before the machine code is returned to
72   /// the allocator.
73   ///
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 *) {}
79
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.
83   ///
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) {}
89
90   /// NotifyFreeingObject - Called just before the memory associated with
91   /// a previously emitted object is released.
92   virtual void NotifyFreeingObject(const ObjectImage &Obj) {}
93
94 #if LLVM_USE_INTEL_JITEVENTS
95   // Construct an IntelJITEventListener
96   static JITEventListener *createIntelJITEventListener();
97
98   // Construct an IntelJITEventListener with a test Intel JIT API implementation
99   static JITEventListener *createIntelJITEventListener(
100                                       IntelJITEventsWrapper* AlternativeImpl);
101 #else
102   static JITEventListener *createIntelJITEventListener() { return 0; }
103
104   static JITEventListener *createIntelJITEventListener(
105                                       IntelJITEventsWrapper* AlternativeImpl) {
106     return 0;
107   }
108 #endif // USE_INTEL_JITEVENTS
109
110 #if LLVM_USE_OPROFILE
111   // Construct an OProfileJITEventListener
112   static JITEventListener *createOProfileJITEventListener();
113
114   // Construct an OProfileJITEventListener with a test opagent implementation
115   static JITEventListener *createOProfileJITEventListener(
116                                       OProfileWrapper* AlternativeImpl);
117 #else
118
119   static JITEventListener *createOProfileJITEventListener() { return 0; }
120
121   static JITEventListener *createOProfileJITEventListener(
122                                       OProfileWrapper* AlternativeImpl) {
123     return 0;
124   }
125 #endif // USE_OPROFILE
126
127 };
128
129 } // end namespace llvm.
130
131 #endif // defined LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H