1 //===- JITEventListener.h - Exposes events from JIT compilation -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the JITEventListener interface, which lets users get
11 // callbacks when significant events happen during the JIT compilation process.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
16 #define LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H
18 #include "llvm-c/ExecutionEngine.h"
19 #include "llvm/Config/llvm-config.h"
20 #include "llvm/ExecutionEngine/RuntimeDyld.h"
21 #include "llvm/IR/DebugLoc.h"
22 #include "llvm/Support/CBindingWrapping.h"
28 class IntelJITEventsWrapper;
29 class MachineFunction;
30 class OProfileWrapper;
36 } // end namespace object
38 /// JITEventListener - Abstract interface for use by the JIT to notify clients
39 /// about significant events during compilation. For example, to notify
40 /// profilers and debuggers that need to know where functions have been emitted.
42 /// The default implementation of each method does nothing.
43 class JITEventListener {
45 using ObjectKey = uint64_t;
47 JITEventListener() = default;
48 virtual ~JITEventListener() = default;
50 /// notifyObjectLoaded - Called after an object has had its sections allocated
51 /// and addresses assigned to all symbols. Note: Section memory will not have
52 /// been relocated yet. notifyFunctionLoaded will not be called for
53 /// individual functions in the object.
55 /// ELF-specific information
56 /// The ObjectImage contains the generated object image
57 /// with section headers updated to reflect the address at which sections
58 /// were loaded and with relocations performed in-place on debug sections.
59 virtual void notifyObjectLoaded(ObjectKey K, const object::ObjectFile &Obj,
60 const RuntimeDyld::LoadedObjectInfo &L) {}
62 /// notifyFreeingObject - Called just before the memory associated with
63 /// a previously emitted object is released.
64 virtual void notifyFreeingObject(ObjectKey K) {}
66 // Get a pointe to the GDB debugger registration listener.
67 static JITEventListener *createGDBRegistrationListener();
69 #if LLVM_USE_INTEL_JITEVENTS
70 // Construct an IntelJITEventListener
71 static JITEventListener *createIntelJITEventListener();
73 // Construct an IntelJITEventListener with a test Intel JIT API implementation
74 static JITEventListener *createIntelJITEventListener(
75 IntelJITEventsWrapper* AlternativeImpl);
77 static JITEventListener *createIntelJITEventListener() { return nullptr; }
79 static JITEventListener *createIntelJITEventListener(
80 IntelJITEventsWrapper* AlternativeImpl) {
83 #endif // USE_INTEL_JITEVENTS
86 // Construct an OProfileJITEventListener
87 static JITEventListener *createOProfileJITEventListener();
89 // Construct an OProfileJITEventListener with a test opagent implementation
90 static JITEventListener *createOProfileJITEventListener(
91 OProfileWrapper* AlternativeImpl);
93 static JITEventListener *createOProfileJITEventListener() { return nullptr; }
95 static JITEventListener *createOProfileJITEventListener(
96 OProfileWrapper* AlternativeImpl) {
99 #endif // USE_OPROFILE
102 static JITEventListener *createPerfJITEventListener();
104 static JITEventListener *createPerfJITEventListener()
111 virtual void anchor();
114 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITEventListener, LLVMJITEventListenerRef)
116 } // end namespace llvm
118 #endif // LLVM_EXECUTIONENGINE_JITEVENTLISTENER_H