Add a JITEventListener interface that gets called back when a new function is
[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_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
16 #define LLVM_EXECUTION_ENGINE_JIT_EVENTLISTENER_H
17
18 #include "llvm/Support/DataTypes.h"
19
20 namespace llvm {
21 class Function;
22
23 /// Empty for now, but this object will contain all details about the
24 /// generated machine code that a Listener might care about.
25 struct JITEvent_EmittedFunctionDetails {
26 };
27
28 /// JITEventListener - This interface is used by the JIT to notify clients about
29 /// significant events during compilation.  For example, we could have
30 /// implementations for profilers and debuggers that need to know where
31 /// functions have been emitted.
32 ///
33 /// Each method defaults to doing nothing, so you only need to override the ones
34 /// you care about.
35 class JITEventListener {
36 public:
37   JITEventListener() {}
38   virtual ~JITEventListener();  // Defined in JIT.cpp.
39
40   typedef JITEvent_EmittedFunctionDetails EmittedFunctionDetails;
41   /// NotifyFunctionEmitted - Called after a function has been successfully
42   /// emitted to memory.  The function still has its MachineFunction attached,
43   /// if you should happen to need that.
44   virtual void NotifyFunctionEmitted(const Function &F,
45                                      void *Code, size_t Size,
46                                      const EmittedFunctionDetails &Details) {}
47
48   /// NotifyFreeingMachineCode - This is called inside of
49   /// freeMachineCodeForFunction(), after the global mapping is removed, but
50   /// before the machine code is returned to the allocator.  OldPtr is the
51   /// address of the machine code.
52   virtual void NotifyFreeingMachineCode(const Function &F, void *OldPtr) {}
53 };
54
55 JITEventListener *createMacOSJITEventListener();
56
57 } // end namespace llvm.
58
59 #endif